Reputation: 5846
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
Reputation: 1060
By including:
'checked' => 'checked',
'default' => 1,
in array, would do the trick.. Voila!
Upvotes: 0
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
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
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