How to display all sub-categories of parent category even if inside sub-category

In WordPress with WooCommerce I want to display all sub-categories of the parent category even if inside the sub-category. When I am in the parent category it works. I am missing something but can’t figure it out.

my code so far

$parentid = get_queried_object_id();
$args = array(
‘parent’ => $parentid
);
$prod_categories = get_terms(
‘product_cat’, $args
);
if ( $prod_categories ) {
echo ‘<ul class=”product-categories”>’;
foreach ( $prod_categories as $prod_category ) {
echo ‘<li class=”category”>’;
//woocommerce_subcategory_thumbnail( $prod_category );
echo ‘<strong>’;
echo ‘<a href=”‘ . esc_url( get_term_link( $prod_category ) ) . ‘” class=”‘ . $prod_category->slug . ‘”>’;
echo $prod_category->name;
echo ‘</a>’;
echo ‘</strong>’;
echo ‘</li>’;
}
echo ‘</ul>’;
}

Read more here:: How to display all sub-categories of parent category even if inside sub-category

Leave a Reply

Your email address will not be published. Required fields are marked *