Skip to main content
1 of 3
Yhis
  • 95
  • 1
  • 2
  • 5

woocommerce: How can I show all the subcategories from a specific category?

I need to show all subcategories using

$product_category = wp_get_post_terms( $post->ID, 'product_cat' );

actually I use:

<?php 
                    global $post;

                    $terms = get_the_terms( $post->ID, 'product_cat', 'hide_empty=0'  );

                  

                    foreach ( $terms as $term ){
                    $category_id = $term->term_id;
                    $category_name = $term->name;
                    $category_slug = $term->slug;

                    echo '<li><a href="'. get_term_link($term->slug, 'product_cat') .'">'.$category_name.'</a></li>';


                    }   



                ?>

it's ok but it shows only the parent category and only one subcategory...

how to fix that?

thanx

Yhis

Yhis
  • 95
  • 1
  • 2
  • 5