【问题标题】:custom woocommerce checkout form fields自定义 woocommerce 结帐表单字段
【发布时间】:2013-07-07 15:04:13
【问题描述】:

我有以下功能在 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?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    你试过了吗:

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

    【讨论】:

      【解决方案2】:

      你当然可以这样做,this plugin

      实际上,您还可以为复选框插入您自己的两个选项。 “是”或“否”等

      【讨论】:

      • 此答案所依赖的链接不再起作用。
      【解决方案3】:

      添加 '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' ));
      

      【讨论】:

        【解决方案4】:

        通过包括:

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

        在数组中,可以解决问题.. 瞧!

        【讨论】:

          猜你喜欢
          • 2023-04-10
          • 1970-01-01
          • 2017-03-21
          • 2015-12-16
          • 1970-01-01
          • 1970-01-01
          • 2015-04-20
          • 2021-07-02
          相关资源
          最近更新 更多