Feature request: Subcategory looper filter

Hi @charlie

I love the fact that Upsells and Crossells loopers are coming!

One commonly needed functionality is often used on Category pages, where we want to display the subcategories of the current category. Unfortunately, there is no native way to filter for those.

I used this code for the custom looper:

//subcategories looper
add_filter('cs_looper_custom_subcat', function($result, $args) 
 {
$category = get_queried_object();
 
  $cat_args = array(
    'hide_empty' => 1,
    'child_of'=> $category->term_id,
    'taxonomy' => 'product_cat', 
  );
  $subcats = get_categories($cat_args);
return $subcats;
}, 10, 2);

That however, doesn’t seem to work always on all websites. I have to dig deeper to find out why. Anyway, this seems to be a logical native option.

Thanks!

4 Likes

That’s a great idea thanks. I think we’re going to do two things here. One is just add a control for child_of query arg. I could see us having a special value here like Current Term. Then adding a “Sub Term” looper helper would be nice.

Have a great weekend!

image

2 Likes

That’s amazing, thank you! Hoping to see it in 7.4 before the official release! :slight_smile:

1 Like