基于类别的woocommerce结帐隐藏字段

问题描述

我在 woocommerce 结帐表单中创建了一些附加字段,并将它们添加到订单摘要中。

现在我希望当购物车中的产品类别不是“choas-group”时,附加字段 (billing_codice_snep) 在两种形式中都隐藏。

我尝试使用此代码,但不起作用。

// Myfunction

 add_filter( 
'woocommerce_checkout_fields','conditionally_remove_checkout_fields',25,1 
 );
function conditionally_remove_checkout_fields( $fields ) {

// HERE the defined product Categories
$categories != array('chaos-group'); 

$found = false;

// CHECK CART ITEMS: search for items from our defined product category
foreach ( WC()->cart->get_cart() as $cart_item ){
    if( has_term( $categories,'product_cat',$cart_item['product_id'] ) ) {
        $found = true;
        break;
    }
}

// If a special category is in the cart,remove some shipping fields
if ( $found ) {

    // hide the billing fields

            unset( $fields['billing']['billing_codice_snep'] );

    
}
return $fields;


   }

谢谢你帮助我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)