• Hi, everyone!

    I have one parent product category – “Balls”
    and two subcategories – “For football”, “For Basketball”

    Parent category shows all products and I have to separate these categories with their titles. For ex:

    PARENT CATEGORY – Balls

    For Footbal

    <ul="products">
    <li></li>
    <li></li>
    and etc.
    </ul>

    For Basketballs

    <ul="products">
    <li></li>
    <li></li>
    and etc.
    </ul>

    I use this part of code that displays the title, but when put it to loop-start.php after <ul class=”products”> it shows only title of the first child category

    <?php
    
            global $post;
    
    	$terms = get_the_terms( $post->ID, 'product_cat', 'hide_empty=0'  );
    
    	foreach ( $terms as $term ) {
    		$category_name = $term->name;
    
    	}
    
    	global $product;
    
    	echo '<h2 class="sub-category-name">'.$category_name.'</h2>';
    ?>

The topic ‘WooCommerce Nested Product Subcategory’ is closed to new replies.