Created
June 3, 2021 05:38
-
-
Save wbcomdev/ae20d9a8808c989ea7fc3aad75a54cf2 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 | |
| /** | |
| * Remove products from a particular category on the shop page. | |
| */ | |
| function wbcom_remove_product_from_specific_category( $q ) { | |
| $tax_query = (array) $q->get( 'tax_query' ); | |
| $tax_query[] = array( | |
| 'taxonomy' => 'product_cat', | |
| 'field' => 'slug', | |
| 'terms' => array( 'music' ), // change or add the category slug here. | |
| 'operator' => 'NOT IN', | |
| ); | |
| $q->set( 'tax_query', $tax_query ); | |
| } | |
| add_action( 'woocommerce_product_query', 'wbcom_remove_product_from_specific_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment