On WooCommerce I am using the archive-product.php template page. I want to show a list of the sub-categorys from the displayed category.
So as the user changes category the list of subcaegories will change to match.
I can get the sub categories for a specific parent category, but I am stuck getting something like if($cat->category_parent == $this)
The code I am using to get subcategorys listed for parent Id=9
<?php
$args = array(
'taxonomy' => 'product_cat',
'orderby' => 'name'
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if($cat->category_parent == 9) {
$category_id = $cat->term_id;
echo '<a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';
}
}
?>
But how do I make it dynamic so each category will show its own subcategories?