Exclude products from a specific category on the shop page

/**
 * Exclude products from a specific category on the shop page
 */
function custom_pre_get_posts_query( $q ) {
if (is_shop()){
    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 't-shirts','shoes' ), // Don't display t-shirts or shoes category on the shop page.
           'operator' => 'NOT IN'
    );


    $q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); 
No Comments

Sorry, the comment form is closed at this time.