gpt4 book ai didi

php - 将城镇/城市文本字段更改为结帐表单中的“选择选项”字段

转载 作者:行者123 更新时间:2023-12-04 14:33:17 24 4
gpt4 key购买 nike

在 Woocommerce 中,我想更改选择字段选项字段中的城镇/城市文本字段。

我该怎么办?

截图如下:

enter image description here

谢谢

最佳答案

您首先需要使用专用工具将字段 type'text' 更改为 'select' Hook woocommerce_default_address_fields。然后,您还必须更改 labeloptions 参数,您将在其中设置城镇在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com