Hiding products with a specific tag from WooCommerce main shop page

I want to hide products with a specific tag from WooCommerce main shop page but not from this same tag dedicated page.

To be clearer, see https//www.popito.fr.

I would like to remove products tagged "pré-commande" from here: https://popito.fr/boutique/ but not from here: https://popito.fr/etiquette-produit/pre-commande/.

Is it doable? If yes, how?

Thanks a lot!

Answers 1

  • You can paste the following snippet in your child theme's functions.php

    function exclude_specific_tag( $q ) {
        if (is_shop()){
            $tax_query = (array) $q->get( 'tax_query' );
            $tax_query[] = array(
                'taxonomy' => 'product_tag',
                'field' => 'slug',
                'terms' => array( 'pré-commande' ), // write the tag name to remove in between the ''
                'operator' => 'NOT IN'
            );
            $q->set( 'tax_query', $tax_query );
        }
    }
    add_action( 'woocommerce_product_query', 'exclude_specific_tag' );
    

Related Questions