我有以下函数向woocommerce结帐表单添加一个选择列表:
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' ));
我想让'NO'选项被默认选中。请建议。怎么做呢?
下面是woocommerce_form_field($key, $args, $value)函数的默认参数($args):
$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' => '',
);
在你的情况下,你只需要这样修改:
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' ));
希望有帮助!