Skip to main content
Question Protected by fuxia
deleted 226 characters in body; edited tags; edited title
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

woocommerce: How can I show Display 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'sIt's ok but it shows only the parent category and only one subcategory...

howHow to fix that?

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?

Display 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?

I need to show all subcategories using

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

$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

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

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?

Source Link
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