自定义计费/运输形式的Placehorlder [英] Customizing placehorlder in billing/shipping forms
问题描述
我正在使用woocommerce_checkout_fields
过滤器来自定义WooCommerce结帐页面中的占位符.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = 'Name';
$fields['billing']['billing_last_name']['placeholder'] = 'Surname';
$fields['billing']['billing_email']['placeholder'] = 'Email';
$fields['billing']['billing_company']['placeholder'] = 'Company Name';
$fields['billing']['billing_phone']['placeholder'] = 'Phone';
$fields['billing']['billing_postcode']['placeholder'] = 'Zip Code';
$fields['billing']['billing_city']['placeholder'] = 'City';
$fields['shipping']['shipping_first_name']['placeholder'] = 'Name';
$fields['shipping']['shipping_last_name']['placeholder'] = 'Surname';
$fields['shipping']['shipping_city']['placeholder'] = 'City';
$fields['shipping']['shipping_postcode']['placeholder'] = 'Zip Code';
return $fields;
}
此功能仅适用于结帐页面表单.
如何在所有运输和开票表格中自定义占位符"?
谢谢.
如果您是在我的帐户"页面中的帐单和寄送"表格中使用,唯一的过滤器挂钩(我知道)可以执行诀窍是:
add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
function custom_form_field_args( $args, $key, $value ) {
// your code
return $args;
};
它位于 wc-template-第1734行上的functions.php ,由my_account
子文件夹,form-edit-address.php
文件(显示表单字段)下的woocommerce模板中的woocommerce_form_field()
函数触发.
这是默认的$args
,您可以使用它来定位要在过滤器功能内进行的更改:
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'autocomplete' => false,
'id' => $key,
'class' => array(),
'label_class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);
注意:通过 Stone 进行的一些更改,它可以正常工作. (请参阅评论).
使用情况:
您可以通过这种方式使用占位符"来定位需要更改的每个占位符:
if ( $args['id'] == 'your_slug1' ) {
$args['placeholder'] = 'your_new_placeholder1';
} elseif ( $args['id'] == 'your_slug2' ) {
$args['placeholder'] = 'your_new_placeholder2';
} // elseif … and go on
帐单和送货地址的占位符通常是相同的...因此您的代码如下:
add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
function custom_form_field_args( $args, $key, $value ) {
if ( $args['id'] == 'your_slug1' ) {
$args['placeholder'] = 'your_new_placeholder1';
} elseif ( $args['id'] == 'your_slug2' ) {
$args['placeholder'] = 'your_new_placeholder2';
} // elseif … and go on
return $args;
};
I am using woocommerce_checkout_fields
filter for customizing the placeholders in WooCommerce checkout page.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = 'Name';
$fields['billing']['billing_last_name']['placeholder'] = 'Surname';
$fields['billing']['billing_email']['placeholder'] = 'Email';
$fields['billing']['billing_company']['placeholder'] = 'Company Name';
$fields['billing']['billing_phone']['placeholder'] = 'Phone';
$fields['billing']['billing_postcode']['placeholder'] = 'Zip Code';
$fields['billing']['billing_city']['placeholder'] = 'City';
$fields['shipping']['shipping_first_name']['placeholder'] = 'Name';
$fields['shipping']['shipping_last_name']['placeholder'] = 'Surname';
$fields['shipping']['shipping_city']['placeholder'] = 'City';
$fields['shipping']['shipping_postcode']['placeholder'] = 'Zip Code';
return $fields;
}
This work fine only for checkout page form.
How to customize 'placeholders' in all shipping and billing forms?
Thanks.
If you mean in My account pages for Billing and Shipping form, the only filter hook (that I know) that could do the trick is:
add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
function custom_form_field_args( $args, $key, $value ) {
// your code
return $args;
};
It is located in wc-template-functions.php on line 1734, triggered by woocommerce_form_field()
function in woocommerce templates under my_account
subfolder, form-edit-address.php
file (displaying the form fields) .
This are the default $args
you can use to target the changes you want to do inside your filter function:
$defaults = array(
'type' => 'text',
'label' => '',
'description' => '',
'placeholder' => '',
'maxlength' => false,
'required' => false,
'autocomplete' => false,
'id' => $key,
'class' => array(),
'label_class' => array(),
'input_class' => array(),
'return' => false,
'options' => array(),
'custom_attributes' => array(),
'validate' => array(),
'default' => '',
);
NOTE: With some changes made by Stone it's working. (see the comment).
USE:
You could use 'placeholder' this way to target each placeholder you need to change:
if ( $args['id'] == 'your_slug1' ) {
$args['placeholder'] = 'your_new_placeholder1';
} elseif ( $args['id'] == 'your_slug2' ) {
$args['placeholder'] = 'your_new_placeholder2';
} // elseif … and go on
The placeholders are generally the same for billing and shipping address… So your code will be like:
add_filter( 'woocommerce_form_field_args', 'custom_form_field_args', 10, 3 );
function custom_form_field_args( $args, $key, $value ) {
if ( $args['id'] == 'your_slug1' ) {
$args['placeholder'] = 'your_new_placeholder1';
} elseif ( $args['id'] == 'your_slug2' ) {
$args['placeholder'] = 'your_new_placeholder2';
} // elseif … and go on
return $args;
};
这篇关于自定义计费/运输形式的Placehorlder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!