JPa*_*shs 2 php wordpress checkout woocommerce hook-woocommerce
我得到此代码以向WooCommerce Billing表单添加自定义字段.
显示该字段但问题是该字段没有label
也placeholder
没有class name
.
我在这里错过了什么?我将此代码添加到我的子主题中的functions.php中.
/*******************************
CUSTOM BILLING FIELD
******************************** */
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields($fields)
{
$fields['billing']['billing_options'] = array(
'label' => __('NIF', 'woocommerce'), // Add custom field label
'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
'required' => false, // if field is required or not
'clear' => false, // add clear or not
'type' => 'text', // add field type
'class' => array('my-css') // add class name
);
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
Rau*_*pta 15
如果您正在使用,
woocommerce_billing_fields
则无需指定将自动分配到开票字段的字段.但是如果你正在使用woocommerce_checkout_fields
那么只需要指定你想要一个字段shipping
或billing
.
对于 woocommerce_billing_fields
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields($fields)
{
$fields['billing_options'] = array(
'label' => __('NIF', 'woocommerce'), // Add custom field label
'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
'required' => false, // if field is required or not
'clear' => false, // add clear or not
'type' => 'text', // add field type
'class' => array('my-css') // add class name
);
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
woocommerce_checkout_fields
add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields($fields)
{
$fields['billing']['billing_options'] = array(
'label' => __('NIF', 'woocommerce'), // Add custom field label
'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
'required' => false, // if field is required or not
'clear' => false, // add clear or not
'type' => 'text', // add field type
'class' => array('my-css') // add class name
);
return $fields;
}
Run Code Online (Sandbox Code Playgroud)
参考:
跳这有帮助!
归档时间: |
|
查看次数: |
14404 次 |
最近记录: |