Php 签出字段-将帐单地址设置为帐单地址1上方的帐单地址2
在WooCommerce结帐字段中,我试图在结帐表单上使账单地址2位于账单地址1之上 因此,与其说是:Php 签出字段-将帐单地址设置为帐单地址1上方的帐单地址2,php,wordpress,woocommerce,field,checkout,Php,Wordpress,Woocommerce,Field,Checkout,在WooCommerce结帐字段中,我试图在结帐表单上使账单地址2位于账单地址1之上 因此,与其说是: Street Address Apartment 我希望: Apartment Street Address 请注意,我使用的主题是Avada 我怎样才能做到这一点 谢谢。更新(与您的评论相关). 这里您有一个附加功能,从Address1字段中删除“Address”文本标签,并将其设置为Address2字段,使该字段(可选)成为必需字段,并稍微更改占位符……我还有另一个解决方案(见下面的代
Street Address
Apartment
我希望:
Apartment
Street Address
请注意,我使用的主题是Avada
我怎样才能做到这一点
谢谢。更新(与您的评论相关).
这里您有一个附加功能,从Address1字段中删除“Address”文本标签,并将其设置为Address2字段,使该字段(可选)成为必需字段,并稍微更改占位符……我还有另一个解决方案(见下面的代码)
代码如下:
add_filter( 'woocommerce_checkout_fields', 'custom_billing_fields_order' );
function custom_billing_fields_order( $fields ) {
// 1. Customizing address_1 and address_2 fields
$fields['billing']['billing_address_1']['label'] = ''; // Removing the label from Adress1
$fields['billing']['billing_address_2']['label'] = __('Address', 'theme_domain');
$fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required
$fields['billing']['billing_address_2']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce');
// 2. Custom ordering the billing fields array (toggling address_1 with address_2)
$custom_fields_order = array(
'billing_first_name', 'billing_last_name',
'billing_company',
'billing_email', 'billing_phone',
'billing_country',
'billing_address_2', 'billing_address_1', ## <== HERE, changed order
'billing_postcode', 'billing_city'
);
foreach($custom_fields_order as $field)
$new_ordered_fields[$field] = $fields['billing'][$field];
// Replacing original fields order by the custom one
$fields['billing'] = $new_ordered_fields;
// Returning Checkout customized billing fields order
return $fields;
}
代码位于活动子主题(或主题)的function.php文件或任何插件文件中
代码经过测试并正常工作
有关答案:
官方文档:检查我之前试过,这是我的第一直觉,但这只是发生了@巴里汉伯里:我必须对此做一点更新……我会在发布时通知你ready@BarryHanbury我已经更新了我的答案…它按预期工作…当我这样做时,我的状态字段消失,行标记混乱。
add_filter( 'woocommerce_checkout_fields', 'custom_billing_fields_placeholders' );
function custom_billing_fields_placeholders( $fields ) {
// 1. Customizing address_1 and address_2 fields
$fields['billing']['billing_address_1']['placeholder'] = __('Apartment, suite, unit etc...', 'woocommerce');
$fields['billing']['billing_address_2']['required'] = true; // Making Address 2 field required
$fields['billing']['billing_address_2']['placeholder'] = __('Street address', 'woocommerce');
// Returning Checkout customized billing fields
return $fields;
}