我正在使用 woocommerce 短代码 [product_categories hide_empty=0] 作为 woocommerce 短代码文档,以在我的商店页面名称 mysitename/sabiresearchshop 中显示我的所有产品类别。但是,我想从显示的产品类别列表中仅排除名为“高级会员”的类别,我该怎么做。
我已尝试以下代码但无济于事:
function sabi_customize_product_shortcode( $args, $atts ) {
if ( is_page (119) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'premium-membership' ),
'operator' => 'NOT IN'
)
);
}
return $args;
}
add_filter( 'woocommerce_shortcode_products_query', 'sabi_customize_product_shortcode', 10, 2 );
这是一个有点老的问题,但我就是这么做的
add_filter( 'woocommerce_product_categories', 'sabi_exclude_category_from_product_categories_shortcode', 10, 1 );
function sabi_exclude_category_from_product_categories_shortcode( $terms ) {
foreach ( $terms as $key => $term ) {
if ( $term->slug == 'premium-membership' ) {
unset( $terms[$key] );
}
}
return $terms;
}