预计阅读时间: 2 分钟

从所有产品短代码中排除类别
假设我们要从每个短代码中删除类别“ black”(请参见上面的示例)。


add_filter( 'woocommerce_shortcode_products_query' , 'bbloomer_exclude_cat_shortcodes');
 
function bbloomer_exclude_cat_shortcodes($query_args){
 
    $query_args['tax_query'] =  array(array( 
            'taxonomy' => 'product_cat', 
            'field' => 'slug', 
            'terms' => array('black'), // Don't display products from this category
            'operator' => 'NOT IN'
        )); 
 
    return $query_args;
}
此文章对你有帮助吗? 已有 0 人说这篇文章是有用的。