Last active
May 6, 2022 00:20
-
-
Save stuartduff/bd149e81d80291a16d4d3968e68eb9f8 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 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
I like to use the code for an adult section that must be hidden from the home page.
But it must be possible to do an order? is that possible?
category "Adult" must be hidden from the main page. But when you search or click on an other page then it must be visible
Is that an option to fix?