Created
October 22, 2020 15:13
-
-
Save omniacode/f95f9459db43ba51a9359d1d09af205c to your computer and use it in GitHub Desktop.
Exclude Specific Product Categories from WooCommerce Shop Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exclude products from a particular category on the shop page | |
function ocs_custom_pre_get_posts_query( $q ) { | |
if( is_shop() || is_page('shop') ) { | |
$tax_query = (array) $q->get( 'tax_query' ); | |
$tax_query[] = array( | |
'taxonomy' => 'product_cat', | |
'field' => 'slug', | |
'terms' => array( 'cat-1', 'cat-2', 'cat-3' ), | |
'operator' => 'NOT IN' | |
); | |
$q->set( 'tax_query', $tax_query ); | |
} | |
} | |
add_action( 'woocommerce_product_query', 'ocs_custom_pre_get_posts_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment