问题
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?
回答1:
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' ));
Hope it helps!
来源:https://stackoverflow.com/questions/40480587/woocommerce-checkout-custom-select-field