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 โBy default, WooCommerce displays products from every category on your main shop page. However, you might want to exclude categories like "Add-ons," "Wholesale," or "Internal Parts" from the general public view. Instead of complex template overrides, you can use the `woocommerce_product_query` action. This allows you to inject a `NOT IN` operator into the taxonomy query, ensuring that products belonging to specific slugs are filtered out of the loop while remaining accessible via direct links or search if needed.
Sometimes you want to keep certain product categories hidden from your WooCommerce shop page. Instead of removing them, use this handy PHP snippet to filter them out easily.
Code to Filter Product Categories on Shop Page
function filter_shop_page_categories( $query ) {
if ( is_shop() ) {
$categories_to_hide = 'your-category-slug'; // Change this to the slug you want to exclude
$tax_query = (array) $query->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( $categories_to_hide ),
'operator' => 'NOT IN',
);
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'filter_shop_page_categories' );
Things to Keep in Mind
You can find more advanced customization options in the WooCommerce query documentation. 
Search our archives or reach out to our team for solutions and expert advice.