Created
April 26, 2023 19:42
-
-
Save nathaningram/0447d2bf809a84f99c716fd21bf6c4f2 to your computer and use it in GitHub Desktop.
Hide Categories from WooCommerce Loop
This file contains 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
// 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