1

I have a small problem creating the settings panel in WordPress with the cmb2 plugin.

I want to create a field in the WooCommerce post type called course headings where each course headings can have a number of Have a title.

and display the product information in the accordion below.

course headings and the titles of each Course titles should be repeatable.

What I was able to do was define repeatable course headings, but I could not add repeatable titles to the headings, and I did not know how to display two foreach loops.

Please help if anyone has experience working with cmb2.

Thanks

code in cmb2 setting

    public function init_metabox() {
        if ( null !== $this->cmb ) {
            return $this->cmb;
        }
        
        $cmb_group_team = new_cmb2_box( array(
            'id'           => 'cmb_group_team',
            'title'        => __( 'course headings setting', 'myprefix' ),
            'context'      => 'normal',
            'priority'     => 'high',
            'object_types' => array('product'),
        ));
        
        $cmb_group_team_item= $cmb_group_team->add_field( array(
            'id'          => 'cmb_group_team_item',
            'type'        => 'group',
            'repeatable'  => true, 
            'options'     => array(
            'group_title'   => 'course headings',
            'closed'     => true,
            ),
        ) );
        
        $cmb_group_team->add_group_field( $cmb_group_team_item, array(
            'name' => 'course headings title',
            'id'   => 'heading_title',
            'type' => 'text',
        ) );
  

        $cmb_group_team->add_group_field( $cmb_group_team_item, array(
            'name' => 'course headings item',
            'id'   => 'heading_values',
            'type' => 'text',
            'repeatable'  => true,
        ) );



code in single-product

            <div id="accordion" class=" mt-4">
         <?php $cmb_group_team_item = get_post_meta(get_the_ID(),'cmb_group_team_item',true);
             $d=1;   foreach($cmb_group_team_item as $team_item) {
               ?>
                    <div class="card borderradius mb-3">
                        <div class="d-flex flex-row card-header justify-content-between py-0 bg-white border border-gray borderradius ">
                        <img src="<?php echo get_template_directory_uri(); ?>/images/Home_03.jpg" class="img-fluid  col-2 col-sm-2 col-md-2 col-lg-1 rounded-circle px-0 py-2">
                            <a href="#education<?php echo $d;  ?>"class="d-flex col-8 col-sm-8 col-md-8 col-lg-10 card-link align-items-center" data-toggle="collapse"><?php echo $team_item['heading_title']?></a>
                            <a href="#education<?php echo $d;  ?>"class="d-flex col-2 col-sm-2 col-md-2 col-lg-1 card-link text-left align-items-center " data-toggle="collapse">
                                <span class="fa fa-chevron-left fa-lg"></span>
                            </a>
                        </div>
                        <div id="education<?php echo $d;  ?>" class="collapse" data-toggle="#accordion">
                            <div class="card-body">
                                <ul>
    
                        <?php    foreach($cmb_group_team_item as $key => $value) { ?>   
                                    <li><?php var_dump($value['heading_values']);  ?></li>
                                    <?php    } ?>
                                </ul>
                            </div>
                        </div>
                    </div>
              <?php  $d++;  } ?>

                    
                </div>

WooCommerce single product page single-post image

0 Answers0