Forked from stuartduff/wc-exclude-product-category-from-shop-page.php
Created
March 13, 2021 21:01
-
-
Save assoscoupa/a282e62ecad68953a0002ee78ee58e7e to your computer and use it in GitHub Desktop.
This snippet will exclude all products from any categories which you choose from displaying on the WooCommerce 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
| function custom_pre_get_posts_query( $q ) { | |
| $tax_query = (array) $q->get( 'tax_query' ); | |
| $tax_query[] = array( | |
| 'taxonomy' => 'product_cat', | |
| 'field' => 'slug', | |
| 'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page. | |
| 'operator' => 'NOT IN' | |
| ); | |
| $q->set( 'tax_query', $tax_query ); | |
| } | |
| add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment