Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 12, 2021 13:54
Show Gist options
  • Select an option

  • Save jorpdesigns/931b38602254e3f6b69f3795fcdf26b4 to your computer and use it in GitHub Desktop.

Select an option

Save jorpdesigns/931b38602254e3f6b69f3795fcdf26b4 to your computer and use it in GitHub Desktop.
Snippet to hide products in specified category from WooCommerce catalogue
<?php
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'category'), // replace with your category slug
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment