Woocommerce product categorie list

Viewed 44

I have a WC shop. On the archive page I have a filter with facet WP. This works great. For the product-categories they want normal links, but only the product-categorie tree of the current main product-categorie. Let me explain a bit more and show you the structure desired.

Bicycle (main sub-categorie)

  • Electrical (sub product-categorie)
  • Race Bikes
    • BMC (sub sub product-categorie)
    • Bianchi
  • Mountain bikes

So when i'm in the main product-categorie 'Bicycle' all other sub product-categories of the main product-category 'Bicycle' must be displayed as a tree. This have to go automatically and for each main product-category. So if i'm in main product-category 'Accesories' all sub product-categories of 'Accessories' have to be displayed as a tree, and clickable to the correct category.

Here's the code I've made:

/** Show subcategories of parent-categories in an unordered list **/
 function wiw_subcats_from_parentcat() { 
 if(is_product_category()) { 
     global $wp_query; 
     $wiw_cat = $wp_query->get_queried_object(); 
     $args = array( 
         //'posts_per_page' => -1,  
         'hierarchical' => 100,  
         'show_option_none' => '',  
         'hide_empty' => 0,  
         'parent' => $wiw_cat->term_id,  
         'taxonomy' => 'product_cat' 
);
$get_subcats = get_categories($args);
echo '<ul class="wiw_cat-parentlist">';
     $term_name = get_term( $wiw_cat->term_id )->name;
     echo '<li><a href="'. $get_link .'">'.$term_name.'</a></li>';
echo '<ul class="wiw_catlist">';
         foreach ($get_subcats as $sc_val)
         {
         $get_link = get_term_link( $sc_val->slug, $sc_val->taxonomy );
         echo '<li><a href="'. $get_link .'">'.$sc_val->name.'</a></li>';
         }
         echo '</ul>';
echo '</ul>';
     }
};

The code i've made, does almost exactly what I want, except the last step goes wrong. When I click on the last sub product-categorie, all other sub product-categories and the main product-categories, are not being displayed anymore. So the visitor can't go back or choose another sub product-category.

The exact same behaviour i would like, see this URL https://www.wehkamp.nl/heren-kleding-jassen/

I'm almost there but missing the last step.

0 Answers
Related