danyo
danyo

Reputation: 5846

custom woocommerce checkout form fields

i have the following function adding a checkbox to the woocommerce checkout form:

woocommerce_form_field( 'email_signup', array(
    'type'          => 'checkbox',
    'class'         => array('input-checkbox'),
    'label'         => __('Newsletter Signup?'),
    ), $checkout->get_value( 'email_signup' ));

I would like to make the checkbox selected by default. Is there a way of doing it through woocommerce form_field options? Or will i need to use javascript?

Upvotes: 1

Views: 4085

Answers (4)

Waqas Shahid
Waqas Shahid

Reputation: 1060

By including:

'checked'       => 'checked',
'default'       => 1,

in array, would do the trick.. Voila!

Upvotes: 0

Steph Moreau
Steph Moreau

Reputation: 169

Adding 'default' => 1 should do the trick

woocommerce_form_field( 'email_signup', array(
'type'          => 'checkbox',
'class'         => array('input-checkbox'),
'label'         => __('Newsletter Signup?'),
'checked'       => 'checked',
'default'       => 1,
), $checkout->get_value( 'email_signup' ));

Upvotes: 5

clickmac
clickmac

Reputation: 1

you can certainly do that, with this plugin

Also you can actually insert your very own two options for checkbox. "Yes" or "No" etc

Upvotes: -1

Rob W
Rob W

Reputation: 9142

Have you tried:

woocommerce_form_field( 'email_signup', array(
'type'          => 'checkbox',
'class'         => array('input-checkbox'),
'label'         => __('Newsletter Signup?'),
'checked'       => 'checked',
), $checkout->get_value( 'email_signup' ));

Upvotes: 1

Related Questions