Grab Link from the product category and display a list with the sub-categories of the Woocommerce product

Asked

Viewed 1,833 times

0

I use this code to display a list of the sub categories of Wordpress posts, I wanted to know how I do to instead of picking the category of posts I pick the category of Woocommerce products.

        <!-- CATEGORIA -->
    <?php $id_da_categoria = get_cat_id('nome da categoria'); 
    $link_da_categoria = get_category_link($id_da_categoria); ?>
    <a href="<?php echo $link_da_categoria ;?>"> CATEGORIA </a>

    <ul>
        <!-- Exibe as sub categorias em uma lista -->
        <?php
        $id_da_categoria = get_cat_id('categoria');
        wp_list_categories('sort_column=name&child_of='."$id_da_categoria".'&title_li=');
        ?>
    </ul>

1 answer

1

You can list categories using the function get_categories(), and pass the parameter taxonomy as product_cat.

Example:

<?php

  $taxonomy     = 'product_cat';
  $orderby      = 'name';

  $args = array('taxonomy' => $taxonomy, 'orderby' => $orderby);

  $product_categories = get_categories( $args );

?>
  • Thanks Fellipe Sores but I could not, I’m beginner and I don’t need anything PHP.

  • In fact what I want is to create a link to when clicking enter the category page and just below this link a list displaying all the sub categories. I don’t know if I’m being clear I apologize if I haven’t made my doubt clear.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.