- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最佳答案
您首先需要使用专用工具将字段 type
从 'text' 更改为 'select' Hook woocommerce_default_address_fields
。然后,您还必须更改 label
和 options
参数,您将在其中设置城镇在 key/values
数组中。
在这个数组中,您将有一条由逗号分隔的城镇线。
代码如下:
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;
}
此代码位于您的事件子主题(或主题)的 function.php 文件中或任何插件文件中。
代码已经过测试并且功能齐全。
更新:要添加您的自定义类,请在 $address_fields['city']['class']…
中替换类 < strong>'my-custom-class'
由你的。
引用资料:
关于php - 将城镇/城市文本字段更改为结帐表单中的“选择选项”字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39698585/
这个问题不太可能帮助任何 future 的访客;它仅与一个小地理区域、一个特定时刻或一个非常狭窄的情况相关,而这些情况通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the
问题 我正在尝试为游戏创建一个城市生成器,该游戏创建具有类型(住宅、工业、商业)的 block 。我所有的街道都是 90 度,因为我希望它是 block 状的(而不是之字形)。 方法 我的第一个方法是
我正在尝试构建一个仅需要显示城市/城镇名称的自动完成文本字段。 所以我想做的是,当有人进入时 是它将显示 Amsterdam Amstelveen 所以它只会显示实际的城市名称,除此之外什么也不显示。
我正在创建一项服务,用户可以在其中访问世界任何地方的地址。首先,我认为 Google Places API 会很高兴,但看看这张图片(下图),问题是如何以正确的顺序过滤掉国家、城镇、街道地址。首先,我
我是一名优秀的程序员,十分优秀!