Created
January 30, 2019 08:47
-
-
Save kartikparmar/ff7ffa7e09fa671c22745cf11d36f43b to your computer and use it in GitHub Desktop.
Remove WooCommerce Product of specific category from shop page
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 | |
| function exclude_product_of_specific_category( $q ) { | |
| if ( is_shop() ) { | |
| $tax_query = (array) $q->get( 'tax_query' ); | |
| $tax_query[] = array( | |
| 'taxonomy' => 'product_cat', | |
| 'field' => 'slug', | |
| 'terms' => array( 'uncategorized' ), // write the slug of category to remove in between the '' | |
| 'operator' => 'NOT IN' | |
| ); | |
| $q->set( 'tax_query', $tax_query ); | |
| } | |
| } | |
| add_action( 'woocommerce_product_query', 'exclude_product_of_specific_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello friend.
It really hidden the products of the specific category in the shop page, thank you very much!
There is a way to hide it from the "father category" too?
Example:
Shop > Others > Hookahs
I want to hide "Hookahs" products from anywhere in the shop, except for its own category, but, it still appearing in the "Others" category.
I want "Hookahs" products only appears in "Hookahs" category.
I need to make a single category with age restriction, after hiding the items I will put a age verification plugin only in this category.
Or, if you have a better idea will be very welcome!
Thank you again.