0

I am working on a theme. Woocommerce categories are displayed on home page but I need to add on shop page, product page and category page.

How can I do this.

1 Answer 1

0

woocommerce is off topic here.

But following code should get all product categories ( sub categories as well ).

Just place it in the template ( where you want categories to appear in )

<?php

  $taxonomy     = 'product_cat';
  $hierarchical = 1; 
  $title        = '';  
  $empty        = 0;

  $args = array(
         'taxonomy'     => $taxonomy,
         'hierarchical' => $hierarchical,
         'title_li'     => $title,
         'hide_empty'   => $empty
  );
 $woo_categories = get_categories( $args );
 foreach ($woo_categories as $cat) {
    if($cat->category_parent == 0) {
        $cat_id = $cat->term_id;       
        echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';

        $args1 = array(
                'taxonomy'     => $taxonomy,
                'child_of'     => 0,
                'parent'       => $cat_id,
                'orderby'      => $orderby,
                'show_count'   => $show_count,
                'pad_counts'   => $pad_counts,
                'hierarchical' => $hierarchical,
                'title_li'     => $title,
                'hide_empty'   => $empty
        );
        $sub_categories = get_categories( $args1 );
        if($sub_categories) {
            foreach($sub_categories as $sub_category) {
                echo '<br /><a href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .'</a>';
            }   
        }
    }       
}
    ?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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