2条回答 默认 最新
- doujiao1949 2016-09-26 09:56关注
You need first to change the field
type
from 'text' to 'select' using the dedicated hookwoocommerce_default_address_fields
. Then you have also to change thelabel
and to and anoptions
argument where you are going to set your towns in an array ofkey/values
.In this array, you will have a line by town separated by a coma.
Here is the code:
add_filter( 'woocommerce_default_address_fields' , 'customize_checkout_city_field' ); function customize_checkout_city_field( $address_fields ) { // Set HERE the cities (one line by city) $towns_cities_arr = array( '0' => __('Select your city', 'my_theme_slug'), 'paris' => 'Paris', 'versailles' => 'Versailles', 'cannes' => 'Cannes', ); // Customizing 'billing_city' field $address_fields['city']['type'] = 'select'; $address_fields['city']['class'] = array('form-row-last', 'my-custom-class'); // your class here $address_fields['city']['label'] = __('Town / city', 'my_theme_slug'); $address_fields['city']['options'] = $towns_cities_arr; // Returning Checkout customized fields return $address_fields; }
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
Update: To add your custom class, replace in
$address_fields['city']['class']…
the class'my-custom-class'
by yours.
References:
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥30 python代码,帮调试
- ¥15 #MATLAB仿真#车辆换道路径规划
- ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
- ¥15 数据可视化Python
- ¥15 要给毕业设计添加扫码登录的功能!!有偿
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条