Woocommerce结帐自定义选择字段

时间:2016-11-08 06:46:45

标签: php wordpress woocommerce hook-woocommerce

我有以下功能将选择列表添加到woo-commerce结帐表单:

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' ));

我想做出“没有”'默认情况下选择的选项。请建议。怎么做?

1 个答案:

答案 0 :(得分:8)

这是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' ));

希望它有所帮助!