1

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!

0

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' );
  • Thanks! It gives me an error: Parse error: syntax error, unexpected end of file in /home/popiatch/public_html/wp-content/themes/xstore-child/functions.php on line 46 (last line of my functions.php)... – Forgaria Jun 20 '18 at 22:31
  • I've updated the snippet, this should work. – Akshat Jun 20 '18 at 22:45
  • then you can accept the answer so it's helpful for another users too. – Akshat Jun 21 '18 at 11:14
  • One last thing though: it works perfectly except for search results where products with the "pré-commande" tag don't appear too... – Forgaria Jun 21 '18 at 11:30
  • you can try to replace (is_shop()) by (is_shop() && !isset($_GET['s'])) – Akshat Jun 21 '18 at 11:38

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.