-1

So I have been able to list all the categories in woocommerce, but I am having trouble trying to list the subcategories of the category 'bathrooms'.

Does anyone have any idea how I can achieve this?

here is the code I am currently using...

<?php $tax_terms = get_terms('product_cat', 'hide_empty=0' ); ?>
        <ul>
          <?php foreach ($tax_terms as $tax_term) {
            echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "%s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
    } ?>
2

You can try this.

$args = array(
     'parent' => 100, // id of the direct parent
     'hide_empty' => false,
);

$cats = get_terms( 'product_cat', $args );

foreach( $cats as $cat ) {
  // do your loop stuff here
}

Here is more information on this function and additional arguments you can use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.