大佬教程收集整理的这篇文章主要介绍了php-结帐字段-使billing_address_2高于billing_address_1,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在WooCommerce结帐字段中,我试图在结帐表单上使billing_address_2高于billing_address_1.
因此,与其说是:
Street Address
Apartment
我想拥有:
Apartment
Street Address
另请注意,我正在使用名为Avada的主题.
我该如何实现?
谢谢.
解决方法:
更新(与您的评论有关)…
在这里,您有一个附加功能,可以从“地址1”字段中删除“地址”文本标签并将其设置为“地址2”字段,也使该字段(可选)成为必需,并稍微更改占位符……我还有另一种解决方案(请参见代码后的下文) ).
这是代码:
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,而不是切换这2个字段,因此您无需对字段重新排序.您可以这样操作:
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文件中,或者在任何插件文件中.
代码已经过测试并且可以正常工作.
相关答案:Checkout fields: Hiding and showing existing fields
官方文件:Customizing checkout fields using actions and filters
以上是大佬教程为你收集整理的php-结帐字段-使billing_address_2高于billing_address_1全部内容,希望文章能够帮你解决php-结帐字段-使billing_address_2高于billing_address_1所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。