首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >除Woocommerce中的特定国家外,所有国家的未设置帐单状态结帐字段

除Woocommerce中的特定国家外,所有国家的未设置帐单状态结帐字段
EN

Stack Overflow用户
提问于 2018-04-04 10:28:34
回答 1查看 1.2K关注 0票数 1

在Woocommerce中,除了结帐页…上的特定国家外,我试图取消所有国家的计费状态字段。

这是我的代码:

代码语言:javascript
运行
复制
add_filter( 'woocommerce_checkout_fields','custom_override_default_address_fields' );
function custom_override_default_address_fields($myfields){
  global $woocommerce;
  $country = $woocommerce->customer->get_billing_country();
  if($country !== 'US' || $country !== 'AU' || $country !== 'CA' || $country !== 'GB'){
    unset( $myfields['billing']['billing_state'] );
  }
  return $myfields;
}

但它并不是真正的…

如何删除除woocommerce中特定国家之外的所有国家的计费状态字段?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-04 15:03:45

似乎您希望删除除美国、非盟、CA和GB以外的所有国家的计费状态,因此这里是这样做的,但它将影响计费状态字段(两者均):

代码语言:javascript
运行
复制
add_filter( 'woocommerce_states' , 'keep_specific_country_states', 10, 1 );
function keep_specific_country_states( $states ) {
    // HERE define the countries where you want to keep
    $countries = array('US', 'AU', 'CA', 'GB');
    $new_country_states = array();

    // Loop though all country states
    foreach( $states as $country_code => $country_states ){
        if( ! in_array( $country_code, $countries ) ){
            // Remove states from all countries except the defined ones
            $states[$country_code] = array();
        }
    }
    return $states;
}

代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49648722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档