Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
Last active March 5, 2025 11:33
Show Gist options
  • Save plugin-republic/5ee4044090513205efa74705f597f035 to your computer and use it in GitHub Desktop.
Save plugin-republic/5ee4044090513205efa74705f597f035 to your computer and use it in GitHub Desktop.
<?php
/**
* Hide product category from main query
* Update line 17 with the slug of the category to be hidden
*/
function pr_product_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$tax_query = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'hoodies' ), // Update the value here
'operator' => 'NOT IN'
)
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'pr_product_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment