1

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

0

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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.