php - WooCommerce 输入选择不采用默认值
问题描述
使用下面的代码,在结帐页面上。圣地亚哥已经被选中,这不是我想要的。我希望默认设置在Seleccione Destino上。
奇怪的是,当我将圣地亚哥的数字从 1 更改为 44 之类的其他数字时,它可以正常工作,它选择 0 作为默认值。当 Santiago 为 1 时,默认值为 Santiago。
我也尝试过设置默认值 1287,但它仍然首先将 1 作为默认值。
add_filter( 'woocommerce_billing_fields', 'add_field', 20, 1 );
function add_field($billing_fields) {
$billing_fields['billing_area'] = array(
'label' => __('Ubicación del Destino', 'woocommerce'),
'required' => true,
'type' => 'select',
'default' => 0,
'class' => array('select'),
'priority' => 65,
'options' => array(
0 => 'Seleccione Ubicación', 1 => 'SANTIAGO', 1287 => 'ACHAO'
)
);
return $billing_fields;
}
解决方案
这应该可以解决问题
function add_field($billing_fields) {
$billing_fields['billing_area'] = array(
'label' => __('Ubicación del Destino', 'woocommerce'),
'required' => true,
'type' => 'select',
'default' => 'seleccione_ubicación',
'class' => array('form-row-wide'),
'priority' => 65,
'options' => array(
'seleccione_ubicación' => 'Seleccione Ubicación',
'santiago' => 'SANTIAGO',
'achao' => 'ACHAO'
)
);
return $billing_fields;
}
add_filter( 'woocommerce_billing_fields', 'add_field', 10, 1 );
推荐阅读
- react-native - 在尝试检索 currentLocation 时,我收到错误“无法读取未定义的属性 'getCurrentPosition'”
- regex - 正则表达式: (#) 和 (? 或 & 或 \n) 之间的所有内容
- python - spacy如何重新训练模型?
- python - 限制cartopy正投影的纬度延伸
- google-cloud-data-fusion - Oracle 标准版和实时管道
- python-3.x - 重定向时如何设置window.alert
- javascript - 如何在javascript中访问另一个对象内的嵌套对象?
- angular - C# Core 和 Angular 7。不适用于 JWT 的 SiganlR 授权
- dynamic - 在 LinkedIn 上分享动态内容
- python - 将张量转换为边缘列表