admin管理员组文章数量:1384332
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.
本文标签: woocommerce offtopicHide a product with a certain tag from productcategory
版权声明:本文标题:woocommerce offtopic - Hide a product with a certain tag from product-category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744523174a2610581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论