在Woocommerce中为结帐表单字段添加类

时间:2018-01-21 05:59:41

标签: php wordpress woocommerce field checkout

我想在checkout表单字段中添加bootstrap form-control类。根据woocommerce文件

function custom_override_checkout_fields( $fields ) {
 $fields['order']['order_comments']['placeholder'] = 'My new placeholder';
 $fields['order']['order_comments']['label'] = 'My new label';
 return $fields;
}

Each field contains an array of properties:

type – type of field (text, textarea, password, select)
label – label for the input field
placeholder – placeholder for the input
class – class for the input
required – true or false, whether or not the field is require
clear – true or false, applies a clear fix to the field/label
label_class – class for the label element
options – for select boxes, array of options (key => value pairs)

技术上如此

$fields['order']['order_comments']['class'] = 'form-control';

应该有效,但我收到警告

implode(): Invalid arguments passed

并且该类未被应用。我做错了什么?

1 个答案:

答案 0 :(得分:1)

explode()函数需要一个数组,因为结帐字段class属性使用数组。

现在,对于需要在字段本身上的bootstrap form-control 类,您将使用未记录的 'input_class' 属性一个数组这样:

$fields['order']['order_comments']['input_class'] = array('form-control');

它会像你期望的那样正常工作(经过测试和运作)。

对于'class'属性,Woocommerce使用以下类:

  • form-row-first(左半场)
  • form-row-last(右侧半场)
  • form-row-wide(全字段)

文档:Customizing checkout fields using actions and filters