doufei9946
2017-11-22 09:44
浏览 77
已采纳

在WooCommerce中为特定国家/地区选择结帐电话字段

I have to display phone as required (mandatory) only if a certain country is selected in WooCommerce checkout screen.

What is the validation rule to check the selected country in real time?

I have tried the following code, which is working for making phone non required:

add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
    $address_fields['billing_phone']['required'] = false;

    return $address_fields;
}

图片转代码服务由CSDN问答提供 功能建议

只有在WooCommerce结帐屏幕中选择了某个国家/地区时,才需要显示电话(必填)。

实时检查所选国家/地区的验证规则是什么?

我尝试过以下代码,该代码适用于非手机操作 必需:

  add_filter('woocommerce_billing_fields','wc_npr_filter_phone',10,1); 
 
function wc_npr_filter_phone($ address_fields){
 $ address_fields ['billing_phone'] ['  required'] = false; 
 
返回$ address_fields; 
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题