Hello, I created an specific woocommerce product category whenre I will add different products that will have an specific discount via plugin.
What I need to do is hide all these products from shop page and then display it in another page.
I found the follwing snippet and added to the child functions.php but it does not work:
/**
* Exclude products from a particular category on the shop page
*/
function custom_pre_get_posts_query( $q ) {
$tax_query = (array) $q->get( ‘tax_query’ );
$tax_query[] = array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => array( ‘come2mexicancaribbean’ ),
‘operator’ => ‘NOT IN’
);
$q->set( ‘tax_query’, $tax_query );
}
add_action( ‘woocommerce_product_query’, ‘custom_pre_get_posts_query’ );
Can you help me please.
Hey Jorge,
Sorry for the late reply, I tested this solution, and it worked on my shop page for the category “uncategorized”.
This looks like the same solution you tried and when I check your shop page I don’t see any items from the “come2mexicancaribbean” category.
Which items are you seeing that should not be there?
Best regards,
Mike