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.
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.
Share Improve this question asked Sep 10, 2018 at 10:32 delta150delta150 32 bronze badges1 Answer
Reset to default 1You 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.