How to control product filter appearance programatically

This tutorial covers how to hide filters on categories for your WooCommerce Shop.

To start this tutorial go to Products > Categories. Here you will see all your categories. 

If you want to hide the filter on one of the categories then you need to choose the slug version of the name. For example, I will choose Cheese.

Now navigate to your child theme and open the functions.php file.

Under the PHP tags put this code:

add_filter( 'prdctfltr_show_filter', 'my_hide_filter_on_category_function_jkbg4iu3b' );

function my_hide_filter_on_category_function_jkbg4iu3b() {
 if ( is_product_category( 'cheese' ) ) {
  return false;
 }
 return true;
}

In the if statement you will put the slug version name of your category. 

Now when we go to our shop and click the Cheese category we will see that our changes have taken effect and that on that category the filter isn’t shown anymore.

Basically you can use any conditional tags here. If you want to add more then one category here is an example of how to do that:

 add_filter( 'prdctfltr_show_filter', 'my_hide_filter_on_category_function_jkbg4iu3b' );


function my_hide_filter_on_category_function_jkbg4iu3b() {
 if ( is_product_category( array( 'robots', 'history' ) ) ) {
  return false;
 }
 return true;
} 

Read more Product Filter for WooCommerce videos to learn more. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

9 comments on “How to control product filter appearance programatically”

  1. Not complete. It still lack of very important possibility to hide filter at top shop level before all named categories – at main shop

    1. You can do anything with WordPress/WooCommerce/Our plugins. It’s all extendable. Just hire a good developer and he’ll fix anything in an hour. If he doesn’t he’s not a good one. Also, if you’re missing an option, it really doesn’t mean that we have to build one for you. We build things that are general. For specific uses, use everything else that’s at your service.