H
H
hypero2021-06-27 17:32:28
WordPress
hypero, 2021-06-27 17:32:28

Display woocommerce categories?

Hello.
I can't display categories on a separate page.
It is necessary to display all categories and subcategories of the main category on which we are located.
That is, for example, they went to the page of the parent category, it is necessary that all child categories are displayed here, then they go to the child and all child categories of the parent category are also displayed here.
There is such code, but it displays subcategories only on the page of the parent category.

<?php $category = get_queried_object();

$args = array(
    'child_of' => $category->term_id,
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
);
$product_categories = get_terms( $args ); 
foreach ( $product_categories as $product_category ) { ?>
    <a href="<?php echo get_term_link( $product_category ); ?>" class="cat-btn"><?php echo $product_category->name; ?></a>
<?php } ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question