自定义woocommerce结帐表单字段

dan*_*nyo 1 php wordpress woocommerce

我有以下功能添加一个复选框到woocommerce结帐表单:

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

我想默认选中复选框.有没有办法通过woocommerce form_field选项来做到这一点?或者我需要使用javascript吗?

Ste*_*eau 5

添加'default'=> 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' ));
Run Code Online (Sandbox Code Playgroud)