yokoyama
yokoyama

Reputation: 67

Display specific option value as default for a select field in WooCommerce

I am adding items using wordpress using woocommerce's woocommerce_form_field function. Therefore, I am using a select box type => select, but I want to display the contents that were decided at the time of initial display.
Example: Assuming that the select box contains the values A, B, and C, I want C to be in the selected state when initially displayed.
How should I specify it?

woocommerce_form_field(
        'XXX',
        array(
            'type'        => 'select',
            'required'    => false, 
            'label'       => 'OO',
            'class'   => array('XXX', 'XXX'),
            'options' => array(
                'a' => 'A',
                'b' => 'B',
                'c' => 'C'
            ),
        ),
    );

Upvotes: 2

Views: 1715

Answers (1)

Paul Franke
Paul Franke

Reputation: 649

You can use the "default" param as argument.

https://rudrastyh.com/woocommerce/woocommerce_form_field.html

woocommerce_form_field(
    'XXX',
    array(
        'type'        => 'select',
        'required'    => false, 
        'label'       => 'OO',
        'class' => array('XXX', 'XXX'),
        'options' => array(
            'a' => 'A',
            'b' => 'B',
            'c' => 'C'
        ),
        'default' => 'c'
    ),
);

Upvotes: 5

Related Questions