Last active
March 5, 2025 11:33
-
-
Save plugin-republic/5ee4044090513205efa74705f597f035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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