2013-07-09 63 views
1

我有以下功能添加一个复选框到woocommerce结账形式:定制woocommerce结账表单字段

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

我想作默认选中的复选框。有没有通过woocommerce form_field选项做到这一点的方法?或者我需要使用JavaScript?

回答

1

你试过:

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

是的不幸这不起作用 – danyo

0

你肯定能做到这一点,与this plugin

而且实际上你可以插入用于复选框你自己的两个选项。 “是” 或 “否” 等

5

添加'默认'=> 1应该做的伎俩

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

通过包括:

'checked'  => 'checked', 
'default'  => 1, 
在阵列

,会做的伎俩。瞧!