Woocommerce结帐自定义选择字段 [英] Woocommerce checkout custom select field
本文介绍了Woocommerce结帐自定义选择字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下功能,在woo-commerce结帐表单中添加了一个选择列表:
I have the following function adding a select list to the woo-commerce checkout form:
woocommerce_form_field( 'airport_pickup', array(
'type' => 'select',
'class' => array('airport_pickup form-row-wide'),
'label' => __('Would you like us to arrange transportation from the airport to your starting hotel?'),
'required' => true,
'options' => array(
'Y' => __('YES'),
'N' => __('NO')
)), $checkout->get_value( 'airport_pickup' ));
我想默认选择否"选项.请提出建议.该怎么做?
I would like to make the 'NO' option selected by default.Please suggest. How to do that?
推荐答案
以下是woocommerce_form_field($ key,$ args,$ value)函数的默认参数($ args):
Here is the default arguments ($args) for the woocommerce_form_field($key, $args, $value) function :
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'autocomplete' => false,
'id' => $key,
'class' => array(),
'label_class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);
在您的情况下,您只需要进行如下修改:
In your case you just need to modify like this:
woocommerce_form_field( 'airport_pickup', array(
'type' => 'select',
'class' => array('airport_pickup form-row-wide'),
'label' => __('Would you like us to arrange transportation from the airport to your starting hotel?'),
'required' => true,
'options' => array(
'Y' => __('YES'),
'N' => __('NO')
),
'default' => 'N'),
$checkout->get_value( 'airport_pickup' ));
希望有帮助!
这篇关于Woocommerce结帐自定义选择字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文