Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save assoscoupa/a282e62ecad68953a0002ee78ee58e7e to your computer and use it in GitHub Desktop.

Select an option

Save assoscoupa/a282e62ecad68953a0002ee78ee58e7e to your computer and use it in GitHub Desktop.
This snippet will exclude all products from any categories which you choose from displaying on the WooCommerce Shop page.
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment