Created
July 12, 2021 13:54
-
-
Save jorpdesigns/931b38602254e3f6b69f3795fcdf26b4 to your computer and use it in GitHub Desktop.
Snippet to hide products in specified category from WooCommerce catalogue
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 | |
| add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); | |
| function custom_pre_get_posts_query( $q ) { | |
| $tax_query = (array) $q->get( 'tax_query' ); | |
| $tax_query[] = array( | |
| 'taxonomy' => 'product_cat', | |
| 'field' => 'slug', | |
| 'terms' => array( 'category'), // replace with your category slug | |
| 'operator' => 'NOT IN' | |
| ); | |
| $q->set( 'tax_query', $tax_query ); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment