在 Woocommerce 中为结帐表单字段添加 class
Add class for checkout form fields in Woocommerce
我想将 bootstrap form-control
class 添加到结帐表单字段。根据 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
并且未应用 class。我做错了什么?
explode()
函数需要一个数组,因为结帐字段 class
属性 使用数组。
现在 bootstrap form-control
class,需要在字段本身上,您将使用未记录的 'input_class'
属性 数组这样:
$fields['order']['order_comments']['input_class'] = array('form-control');
它会按您预期的那样正常工作(已测试并有效)。
对于 'class'
属性,Woocommerce 使用以下 classes:
form-row-first
(左边半场)
form-row-last
(右边半场)
form-row-wide
(满场)
我想将 bootstrap form-control
class 添加到结帐表单字段。根据 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
并且未应用 class。我做错了什么?
explode()
函数需要一个数组,因为结帐字段 class
属性 使用数组。
现在 bootstrap form-control
class,需要在字段本身上,您将使用未记录的 'input_class'
属性 数组这样:
$fields['order']['order_comments']['input_class'] = array('form-control');
它会按您预期的那样正常工作(已测试并有效)。
对于 'class'
属性,Woocommerce 使用以下 classes:
form-row-first
(左边半场)form-row-last
(右边半场)form-row-wide
(满场)