在WooCommerce签出字段中,我试图在签出表单上使billing_address_2高于billing_address_1。
所以与其说它是:
Street Address
Apartment我希望:
Apartment
Street Address请注意,我使用的主题叫做Avada。
我怎样才能做到这一点?
谢谢。
发布于 2017-02-06 13:05:07
更新(与您的评论相关)…
这里添加了一个从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;
}而不是切换这两个字段,您可以反转字段占位符并添加make (可选)字段Address2,因此不需要重新排序字段。你可以这样做:
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;
}代码在您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。
代码经过测试和工作。
相关答案:签出字段:隐藏和显示现有字段
正式文件:使用操作和过滤器自定义签出字段
https://stackoverflow.com/questions/42067445
复制相似问题