Skip to content
Advertisement

WooCommerce 3.x – Hide category of product

I would like to know if anyone has a clue on how to hide a specific product category all around my website. Means on the “shop”, “related product” and the “search” of my WordPress WooCommerce website.

For the “shop” pages I have done (and it’s working) the following:

JavaScript

For the search I tried the following but it doesn’t work:

JavaScript

add_filter(‘pre_get_posts’,’exclude_category_from_search’);

Finally, for the related product I tried the following which seems deprecated since WC 3.x:

JavaScript

I also have in my child-theme the following:

JavaScript

And I know that we can hide product category with this part of code that I used on other classes:

JavaScript

Anyone have an idea on how to do that with the new version of WoomCommerce? I’ve made a lot of research around but all looks like deprecated answer since this new version.

PS: I need to keep this category as I am using it to create some composite products, so only hide these products but not remove them .

Cheers

Advertisement

Answer

To exclude your category (“Carton” here) from search and SHOP page, add the following in my function.php file of my child theme:

JavaScript

Regarding the “related products”, I had to tweak it but in the end it’s improving the related coming with woocommerce. I am basically sorting my related product by order of brand, category & season. Because “Carton” is a category, it doesn’t retrieve any of them:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement