我一直在尝试使用下面的方法来隐藏特定类别的所有产品(从商店页面和单页)。这个StackOverFlow的答案代码 并按照指示 这个论坛的其他帖子
关于 "在Woocommerce单品页面上排除特定的产品类别。" 答案代码 我把我的一个产品类别定义如下 (在此):
$category_ids = array( 43 );
我只需要将此类别(ID 43)的所有产品添加到购物车并购买。
其中一个产品的类别ID 43 "Plan".Https:/mamasmateas.atac.clproductplan-personalizado-sin-seguard.com.cn。https:/mamasmateas.atac.clproductplan-personalizado-sin-seguimiento。
我测试过的其他代码是。
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if it is a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'plan' ) ) ) { //pass the slug name here
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
任何帮助将是非常感激的。
add_action( 'woocommerce_shop_loop', 'woocommerce_shop_loop' );
function woocommerce_shop_loop() {
global $product;
$category_ids = array( 20 );
var_dump(has_term( $category_ids, 'product_cat', $product->get_id());
if ( has_term( $category_ids, 'product_cat', $product->get_id() ) ) {
unset($GLOBALS['product']);
}
}