When managing an online store in WooCommerce, you may find the need to hide certain product categories from search results. This could be due to various reasons, such as seasonal promotions, exclusive items, or simply organizing your product listings better. Whatever your reasons, learning how to hide a WooCommerce category from search results is a handy skill for any WooCommerce site administrator. This guide will walk you through the steps necessary to achieve this functionality smoothly and effectively.
Understanding the Need to Hide Categories
Before diving into the technical aspects, it’s important to understand why someone might want to hide a WooCommerce category from search results. For instance, if you’re running exclusive deals that you only want certain customers to access via direct links, hiding these categories from general search results can control the visibility of these deals. Another common reason is to streamline search results by removing irrelevant or less important product categories to enhance user experience.
Implementing the Code to Hide Categories
To hide a WooCommerce category from search results, you can add a snippet of code to your theme’s functions.php file. This code will modify the search query to exclude products from specific categories.
Step 1: Identify the Category
First, you need to identify the category ID that you want to hide. You can find this by going to the “Products” > “Categories” section in your WordPress dashboard and hovering over the category to see its ID.
Step 2: Add Code to Your Theme’s Functions.php
Open your WordPress dashboard, go to Appearance > Theme Editor, and select the functions.php file of your active theme. Insert the following code at the end of the file:
/*
* Snippet: How to Hide a WooCommerce Category from Search Results – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1092
* Tested with WooCommerce 10.7.0
*/
function wcsuccess_hide_category_from_search($query) {
if ( !is_admin() && $query->is_main_query() && $query->is_search() ) {
$query->set('tax_query', array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => array(10), // Replace '10' with your category ID
'operator' => 'NOT IN',
)
));
}
}
add_action('pre_get_posts', 'wcsuccess_hide_category_from_search');
Replace 'terms' => array(10) with the ID of the category you want to exclude from search results.
How to Hide a WooCommerce Category from Search Result
The code snippet provided works by hooking into the WordPress pre_get_posts action, which alters the main query that WordPress runs to fetch posts. By modifying this query, we can exclude specific categories from search results effectively. This solution ensures that when customers search for products on your site, they won’t see products from the categories you’ve hidden.
Best Practices
When you choose to hide a WooCommerce category from search results, keep these best practices in mind:
- Update Regularly: Ensure that the category IDs are updated if you make changes to your categories.
- Test Your Changes: Always test your website after making changes to ensure that the search functionality works as expected and that the right categories are being hidden.
- Inform Your Team: Make sure that everyone managing your store is aware of the changes, especially if you are hiding categories for reasons like limited promotions or exclusive products.
Conclusion
Knowing how to hide a WooCommerce category from search results is a valuable skill for managing an e-commerce store. It helps in customizing the shopping experience and managing the visibility of specific product categories. By following the steps outlined in this post, you can effectively control what shows up in your store’s search results, enhancing both user experience and your store’s operational efficiency.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

