• I have searched and can’t seem to find a solution for this situation.

    I have level 1, 2, and 3 categories like:

    Backpacks
    -Hydration
    –Hi Viz
    –Camo

    What I want to accomplish is when the user clicks on a level 1 category they can see all sub categories listed rather than products (I am calling these level 2). Then, when they click on a sub category I want it to display all 3rd level categories rather than the products.

    Right now it is displaying the first two categories as requested but I can’t find an option to have it display categories 3 levels deep. I’ve even searched plugins.

    So say they click on Backpacks (level 1) they currently see all sub-categories like Hydration for example. I then want it to display another layer of categories if they were to click Hydration. I am not sure on the technical name of this 3rd level category set but hope the above explanation explains well enough what I am trying to accomplish.

    Is there some setting on WooCommerce settings that I am not seeing? Is there a plugin that can accomplish this if not?

    Any feedback would be greatly appreciated!s

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi 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,

    Hi melves901

    Where abouts do you insert this code?
    e.g. Template – which template? etc.

    Regards

    errrrs

    (@errrrs)

    Hey Melves901, I know this is a little old now but i was wondering if you knew how to get the category image for the categories. Ive got it to work for second level categories but I am targeting a specific 3rd level category to display on a page.. Anything that could help.

    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Showing 3rd level category list’ is closed to new replies.