Skip to content

Instantly share code, notes, and snippets.

@nathaningram
Created April 26, 2023 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathaningram/0447d2bf809a84f99c716fd21bf6c4f2 to your computer and use it in GitHub Desktop.
Save nathaningram/0447d2bf809a84f99c716fd21bf6c4f2 to your computer and use it in GitHub Desktop.
Hide Categories from WooCommerce Loop
// Add the code to your theme's functions.php file
function exclude_categories_from_shop_page( $query ) {
if ( ! is_admin() && is_shop() && $query->is_main_query() ) {
$tax_query = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('unlimited-power', 'weapons'),
'operator' => 'NOT IN'
)
);
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts', 'exclude_categories_from_shop_page' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment