在Woocommerce中添加运输区域的状态而不是邮政编码 [英] Add states for shipping zones instead of postcodes in Woocommerce

查看:128
本文介绍了在Woocommerce中添加运输区域的状态而不是邮政编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个woocommerce网站。在woocommerce中,默认情况下,我可以通过邮政编码限制运输区域...。但是,如何在运输区域中添加我所在国家的州,以便客户可以在结帐页面中通过下拉菜单选择居住的州,而不用输入邮政编码?



我是编码新手,所以有人可以告诉我在哪里也可以输入编码。



请...

解决方案

如果在woocommerce中未为您的国家/地区定义州,则应该使用字母代码(2或3个大写字符)和数组中的相应标签名称。



以下是基于法国地区的示例(未在Woocommerce)(法国国家代码 'FR' (因此您需要设置woocommerce国家代码)) >:

  add_filter('woocommerce_states','add_custom_states_to_country'); 
add_filter(‘woocommerce_countries_allowed_country_states,‘add_custom_states_to_country’);
函数add_custom_states_to_country($ states){
$ states ['FR'] = array(
'AR'=> __('Auvergne-Rhône-Alpes','woocommerce'),
'BF'=> __('Bourgogne-Franche-Comté','woocommerce'),
'BR'=> __('Bretagne','woocommerce'),
'CV'=> __('Centre-Val-de-Loire','woocommerce'),
'CO'=> __('Corse','woocommerce'),
'IF '=> __('法兰西岛','woocommerce'),
'GE'=> __('Grand Est','woocommerce'),
'HF'=> ; __('Hauts-de-France','woocommerce'),
'NO'=> __('Normandie','woocommerce'),
'NA'=> __(' Nouvelle-Aquitaine','woocommerce'),
'OC'=> __('Occitanie','woocommerce'),
'PL'=> __('卢瓦尔河上付款', 'woocommerce'),
'PA'=> __('Provence-Alpes-Côted'Azur','woocommerce'),
);
返回$ states;
}

代码进入活动子主题(或活动主题)的function.php文件)。经过测试并可以正常工作。





购物车中(运费计算器):





结帐:




I have a woocommerce website. by default in woocommerce i can limit shipping zones by zipcode.... But How can I add states of my country in shipping zones so that customers can choose the state they live by a "dropdown menu" in checkout page instead of entering zip code ?

I'm new to coding, so can someone pls tell me where to enter the codes as well.

Please...

解决方案

If states are not defined for your country in woocommerce, you should need to defined them all with a letter code (2 or 3 uppercase characters) and the corresponding label name in an array.

Here bellow is an example based on France regions (Not defined in Woocommerce) for France country code 'FR' (so you need to set your woocommerce country code):

add_filter('woocommerce_states', 'add_custom_states_to_country');
add_filter('woocommerce_countries_allowed_country_states', 'add_custom_states_to_country');
function add_custom_states_to_country( $states ) {
    $states['FR'] = array(
        'AR' => __('Auvergne-Rhône-Alpes', 'woocommerce'),
        'BF' => __('Bourgogne-Franche-Comté', 'woocommerce'),
        'BR' => __('Bretagne', 'woocommerce'),
        'CV' => __('Centre-Val-de-Loire', 'woocommerce'),
        'CO' => __('Corse', 'woocommerce'),
        'IF' => __('Île-de-France', 'woocommerce'),
        'GE' => __('Grand Est', 'woocommerce'),
        'HF' => __('Hauts-de-France', 'woocommerce'),
        'NO' => __('Normandie', 'woocommerce'),
        'NA' => __('Nouvelle-Aquitaine', 'woocommerce'),
        'OC' => __('Occitanie', 'woocommerce'),
        'PL' => __('Pays de la Loire', 'woocommerce'),
        'PA' => __('Provence-Alpes-Côte d’Azur', 'woocommerce'),
    );
    return $states;
}

Code goes in function.php file of your active child theme (or active theme). tested and works.

The Country Iso Codes


In Shipping Zone Settings:

In Cart (shipping calculator):

In Checkout:

这篇关于在Woocommerce中添加运输区域的状态而不是邮政编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆