Skip to content

Instantly share code, notes, and snippets.

@shahzaibkhan
Created July 21, 2022 11:25
Show Gist options
  • Save shahzaibkhan/98bdfcda94adf024fb34cd2053e4af99 to your computer and use it in GitHub Desktop.
Save shahzaibkhan/98bdfcda94adf024fb34cd2053e4af99 to your computer and use it in GitHub Desktop.
prefix_custom_pre_get_posts_query
function prefix_custom_pre_get_posts_query( $q ) {
if( is_shop() || is_page('awards') ) { // set conditions here
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment