Display Woocommerce Category Thumbnail Archive Page

I think my confusion is where to place everything. Would it be possible for you to provide screencaps that are a little wider so I have better context of where to place the bits of code?

Sorry, I know it’s probably frustrating to deal with less-technical developers… hahah

Hi @Nuera,

No problem to describe you again, but the instructions are already given in the reference thread which I have given in my previous post. You need to add the PHP code into your child theme’s functions.php file. Then you need to select the Looper Provider type Custom and add the subcat as Hook and add the parameter into the Param section as shown in the following screenshot.

If you have any further confusion, I would suggest you to go through the reference thread in above posts.

Thanks

That makes sense, thanks for the clarification!

I have edited the functions.php and I have added the code in the JSON bit. It’s now displaying all of the subcategories which is a great step forward!

Now I just need the Subcategories to display based on the Category that’s selected. Right now it is simply displaying all of the subcategories instead of the specific subset.

I tried to reference the link you included earlier, but it is 404’ing, so feel free to resend if you have an active link and I’ll be more than happy to dive into it.

Hi Nuera,

I just check your setup and found out why they are not showing the specific subcategory of the main category. The main problem here is that the code you added in your child theme functions.php.

add_filter('cs_looper_custom_subcat', function($result, $args) 
{    
    $term_id = cs_dynamic_content( $args['parent_cat'] );      
	
    $cat_args = array(
        'hide_empty' => 1,
        'child_of'=> $term_id,
        'taxonomy' => 'product_cat',
        
    );    
    $subcats = get_categories($cat_args);
    return $subcats;
}, 10, 2);

The $term_id on that code is empty that’s why it is showing all the categories and subcategories. To fix your issue, please update your code to this one.

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 code will do the trick. It will display the sub-category of the specific main category.

Hope that helps.

Thank you.

1 Like

WOOO!!! That’s PERFECT.

Thank you all so much!!!

You are most welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.