I want to remove certain products by their tag from woocommerce Shop page query. Anyone can tell me how to do that? Thanks!

1 Answer
Add this to your functions.php
function custom_pre_get_posts_query( $q ) { $tax_query = (array) $q->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => array( 'banana' ), // Don't display products with the tag "banana" 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );