內容簡介
WooCommerce使用文本輸入是讓客戶輸入城市或鎮的。透過這個外掛,您可以提供一個城市列表來顯示為下拉式選單。
這將顯示在結帳頁面、編輯地址頁面和運費計算機(如果已設定)。
如何添加城市
城市清單必須在functions.php文件中加載(外掛已經包含了一些國家的城市列表)。
使用 wc_city_select_cities 過濾器來加載您的城市。這是類似於添加州/省的方式進行的。
它應該添加在您的functions.php文件或自定義插件中。
add_filter( 'wc_city_select_cities', 'my_cities' );
/**
* 用國家代碼替換XX。代替YYY, ZZZ,使用實際州/省代碼。
*/
function my_cities( $cities ) {
$cities['XX'] = array(
'YYY' => array(
'City ',
'Another City'
),
'ZZZ' => array(
'City 3',
'City 4'
)
);
return $cities;
}
也可以使用一個城市列表,而不把它們按州/省分組:
add_filter( 'wc_city_select_cities', 'my_cities' );
function my_cities( $cities ) {
$cities['XX'] = array(
'City ',
'Another City'
);
return $cities;
}
Github
源代碼和貢獻位於 Github
外掛標籤
開發者團隊
原文外掛簡介
WooCommerce uses a text input for the customers to enter the city or town. With this plugin you can provide a list of cities to be shown as a select dropdown.
This will be shown in checkout pages, edit addresses pages and shipping calculator if it’s configured that way.
WooCommerce Cart and Checkout Blocks
This plugin is not yet compatible with Blocks.
It works using the legacy shortcodes: [woocommerce_cart] and [woocommerce_checkout].
To make this plugin work, you can use these shortcodes instead of the blocks for your Cart and Checkout pages.
How to add cities
A list of cities has to be loaded in the functions.php file (the plugin already includes cities from some countries).
Use wc_city_select_cities filter to load your cities. This is done similarly to adding states/provinces.
It should be added on your functions.php or a custom plugin.
add_filter( 'wc_city_select_cities', 'my_cities' );
/**
* Replace XX with the country code. Instead of YYY, ZZZ use actual state codes.
*/
function my_cities( $cities ) {
$cities['XX'] = array(
'YYY' => array(
'City ',
'Another City'
),
'ZZZ' => array(
'City 3',
'City 4'
)
);
return $cities;
}
It’s also possible to use a list of cities without grouping them by state:
add_filter( 'wc_city_select_cities', 'my_cities' );
function my_cities( $cities ) {
$cities['XX'] = array(
'City ',
'Another City'
);
return $cities;
}
Github
Source code and contributions at github
