从产品查询中排除自定义分类
在 woocommerce 安装中,我添加了产品的自定义分类法。其中之一是带有“促销”一词的季节。
我想从商店页面中排除这些促销商品。所以我使用了下面的函数,但它似乎不起作用。该函数实际上适用于自定义分类法吗?
源代码: https://woocommerce.com/document/从商店页面中排除类别/
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
global $woocommerce;
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'season', // taxonomy
'field' => 'slug',
'terms' => array( 'sale' ), //slug taxonomies
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
In a woocommerce installation I added custom taxonomies for products. One of them is season with a term 'sale'.
I want to exclude these sale items from the shop page. So I used below function, but it doesn't seem to work. Is this function actually working for a custom taxonomy?
Source code: https://woocommerce.com/document/exclude-a-category-from-the-shop-page/
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
global $woocommerce;
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'season', // taxonomy
'field' => 'slug',
'terms' => array( 'sale' ), //slug taxonomies
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论