自定义 woocommerce 结帐表单字段

Posted

技术标签:

【中文标题】自定义 woocommerce 结帐表单字段【英文标题】:custom woocommerce checkout form fields 【发布时间】: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

【问题讨论】:

【参考方案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,

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

【讨论】:

以上是关于自定义 woocommerce 结帐表单字段的主要内容,如果未能解决你的问题,请参考以下文章

如何在 woo commerce 的结帐表单字段中删除额外的 div html 类

自定义 woocommerce 结帐表单字段

Drupal,Ubercart - 将自定义字段添加到结帐表单

php 重新排序结帐字段#woo

php 结帐:删除字段#woo #hide

如何自定义 magento 单页结帐表单