12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Mar 4, 2022

How to Exclude Specific Product Categories from the WooCommerce Shop Page

Sridhar Katakam

Looking to exclude one or more product categories from appearing on the main Shop page when using WooCommerce?

Add the code below either using Code Snippets plugin or in your active theme’s functions.php.

add_action( 'woocommerce_product_query', 'wpdd_exclude_product_cat_from_wc_shop' );
/**
 * Exclude selected product category/categories from the main WooCommerce Shop page
 * 
 * @param object $query data
 *
 */
function wpdd_exclude_product_cat_from_wc_shop( $query ) {	
	if ( $query->is_main_query() && ! is_admin() && $query->is_post_type_archive( 'product' ) ) {
		$query->set( 'tax_query', array(array(
			'taxonomy' => 'product_cat',
			'field' => 'slug',
			'terms' => array( 'tshirts' ), // Enter comma-separated slugs of product categories to be excluded here
			'operator' => 'NOT IN'
		)));
	}
}

Replace tshirts in the above with the slug of a product category that you wish to not include.

For excluding multiple product categories, you’d change it to something like:

'terms' => array( 'tshirts', 'decor' ),

If you are using Oxygen make sure that the Query Type of Products List component is left at default.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right