0

I am trying to make products with a certain tag disappear completely from the store, including when customers are browsing categories.

In another question I found this function that help me hide products on the shop page, which is great.

    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( 'special' ), // tag name to hide ''
            'operator' => 'NOT IN'
        );
        $q->set( 'tax_query', $tax_query );
    }
}
add_action( 'woocommerce_product_query', 'exclude_specific_tag' );

Now I need to hide that certain tag from product-categories. The goal is to hide these products with the tag completely from the store, unless I show them in a specific page or post.

Any help and answers are greatly appreciated.

0

You should be able to add to your condition:

if (is_shop() || is_product_category()) {

This will exclude products with the tag from both the shop page and all product categories. You may also want to add || is_product_tag() to make sure they don't show up on tag archives. WooCommerce's conditional tags reference can help you find all the conditions you may be interested in using.

  • Thank you so much. Adding is_product_category to the function did exactly what I was looking for. I also added that last piece you recommended :) – delta150 Sep 12 '18 at 1:04

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.