Home » WooCommerce: Hide Products From Specific Category @ Shop

WooCommerce: Hide Products From Specific Category @ Shop

by Tutor Aspire

A very handy snippet. Sometimes, you only want to show certain categories on the shop page, and have those products ONLY show under the category archive instead.

WooCommerce: hide products belonging to a specific category

PHP Snippet: Hide Products From Specific Category @ Shop – WooCommerce

/**
 * @snippet       Hide Products From Specific Category @ Shop
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 3.6.3
 * @donate $9     https://www.tutoraspire.com
 */
 
add_action( 'woocommerce_product_query', 'tutoraspire_hide_products_category_shop' );
  
function tutoraspire_hide_products_category_shop( $q ) {
 
    $tax_query = (array) $q->get( 'tax_query' );
 
    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'chairs' ), // Category slug here
           'operator' => 'NOT IN'
    );
 
 
    $q->set( 'tax_query', $tax_query );
 
}

You may also like