melves901
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [WooCommerce] Showing 3rd level category listHi One2!
Here is what I have made to make this work.
<?php $taxonomy = 'product_cat'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $empty = 0; $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); ?> <ul> <?php $all_categories = get_categories( $args ); foreach ($all_categories as $cat) { if($cat->category_parent == 0) { $category_id = $cat->term_id; echo '<li><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .' <span class="count">('. $cat->count .')</span></a>'; $args2 = array( 'taxonomy' => $taxonomy, 'child_of' => 0, 'parent' => $category_id, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); $sub_cats = get_categories( $args2 ); if($sub_cats) { echo '<ul>'; foreach($sub_cats as $sub_category) { $category_sub_id = $sub_category->term_id; echo '<li><a href="'. get_term_link($sub_category->slug, 'product_cat') .'">'. $sub_category->name .' <span class="count">('. $sub_category->count .')</span></a>'; $args3 = array( 'taxonomy' => $taxonomy, 'child_of' => 0, 'parent' => $category_sub_id, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); $sub_cats_sub_cats = get_categories( $args3 ); if($sub_cats_sub_cats) { echo '<ul>'; foreach($sub_cats_sub_cats as $sub_cat_sub_category) { echo '<li><a href="'. get_term_link($sub_cat_sub_category->slug, 'product_cat') .'">'. $sub_cat_sub_category->name .' <span class="count">('. $sub_cat_sub_category->count .')</span></a></li>'; } echo '</ul>'; } echo '</li>'; } echo '</ul>'; } echo '</li>'; } } ?> </ul>
Let me know if this work for you.
Regards,
Viewing 1 replies (of 1 total)