admin管理员组文章数量:1318770
In my wooCommerce shop, I've 2 taxonomy
1. Product Category
2. Services Category
Shop page is showing up all products from both categories. I want to exclude products from SHOP & Search Results page which are in the Services Category.
Is this thing car be achieved by pre_get_posts ? but I think it will not on work with the wooCommerce shop page.
Let me know what is the best approach to do this. any hooks or actions for this.
Thank you. Any help would be appreciated.
In my wooCommerce shop, I've 2 taxonomy
1. Product Category
2. Services Category
Shop page is showing up all products from both categories. I want to exclude products from SHOP & Search Results page which are in the Services Category.
Is this thing car be achieved by pre_get_posts ? but I think it will not on work with the wooCommerce shop page.
Let me know what is the best approach to do this. any hooks or actions for this.
Thank you. Any help would be appreciated.
Share Improve this question asked Oct 20, 2020 at 18:45 Danish MohammedDanish Mohammed 135 bronze badges1 Answer
Reset to default 1This might help you with Shop page listing:
https://docs.woocommerce/document/exclude-a-category-from-the-shop-page/
And for Search page, here is a snippet that might help:
function exclude_services_category_products_from_search( $query ) {
if ( is_search() && !is_admin() ) {
$array_with_service_category_id = [];
$tax_query = $query->get( 'tax_query' ) ?: [];
$tax_query[] = [
'taxonomy' => 'product_cat',
'terms' => $array_with_service_category_id,
'field' => 'term_id',
'operator' => 'NOT IN'
];
$query->set( 'tax_query', $tax_query );
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_services_category_products_from_search' );
Just add the Service Category id in the $array_with_service_category_id array.
本文标签: hooksHow to exclude a taxonomy from shop amp search page wooCommerce
版权声明:本文标题:hooks - How to exclude a taxonomy from shop & search page wooCommerce? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742043073a2417636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论