Create Custom Menu in WordPress Dashboard
Complete tutorial on create custom menu in wordpress dashboard. Discover practical examples, implementation tips, and expert advice for WordPress and WooCo
Read More →
Sometimes, you may want to prevent certain product categories from appearing on your WooCommerce shop page without deleting them or affecting their visibility elsewhere. You can achieve this easily by modifying the WooCommerce product query using the woocommerce_product_query hook. Below is a quick guide to help you exclude specific product categories from showing up on the shop page. Follow the steps below to exclude a product category from the shop page:
function exclude_category_from_shop( $q ) {
if ( is_shop() ) {
// Replace 'category-slug-to-hide' with the actual slug of the category you want to hide
$category_slug_to_exclude = 'category-slug-to-hide';
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( $category_slug_to_exclude ),
'operator' => 'NOT IN',
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'exclude_category_from_shop' );
How Does This Work?
This code works by hooking into the WooCommerce product query and modifying the tax query to exclude products from a specific category on the shop page. By replacing 'category-slug-to-exclude' with the slug of the category you want to hide, you'll ensure that no products from that category appear on the shop page.
Key Considerations
For more details on customizing product queries in WooCommerce, check out this WooCommerce Query Variables Guide.
Conclusion
With just a few lines of code, you can hide specific product categories from showing up on your WooCommerce shop page, giving you greater flexibility in how you display products. This method doesn’t affect any other parts of your site, ensuring a smooth user experience.

Search our archives or reach out to our team for solutions and expert advice.