php – 自定义Woocommerce 3中的我的帐户地址字段
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 自定义Woocommerce 3中的我的帐户地址字段,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2412字,纯文字阅读大概需要4分钟。
内容图文
![php – 自定义Woocommerce 3中的我的帐户地址字段](/upload/InfoBanner/zyjiaocheng/711/68bed029c7544382ac859966a7d01d1c.jpg)
我想删除模板form-edit-addresses.php中的表单字段billing_adress_2.
要完成,可以重新排序表单字段,如下所示:
first_name – last_name
电子邮件 – 电话
公司
地址1
邮编
市
州
这个改变我想只在页面(模板)form-edit-addresses.php上应用它
任何帮助表示赞赏
解决方法:
在我的帐户中>地址部分,下面挂钩的功能将:
>删除“地址2”结算和发货字段
>重新订购帐单和送货地址字段
>重新订购计费电子邮件和电话字段(在名字和姓氏之后)
>从显示中删除“地址2”
您忘记了可以在$sorted_fields数组中轻松重新排序的“country”字段…
编码:
// Account Edit Adresses: Remove and reorder addresses fields
add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields', 20, 1 );
function custom_default_address_fields( $fields ) {
// Only on account pages
if( ! is_account_page() ) return $fields;
## ---- 1. Remove 'address_2' field ---- ##
unset($fields['address_2']);
## ---- 2. Sort Address fields ---- ##
// Set the order (sorting fields) in the array below
$sorted_fields = array('first_name','last_name','company','address_1','country','postcode','city','state');
$new_fields = array();
$priority = 0;
// Reordering billing and shipping fields
foreach($sorted_fields as $key_field){
$priority += 10;
if( $key_field == 'company' )
$priority += 20; // keep space for email and phone fields
$new_fields[$key_field] = $fields[$key_field];
$new_fields[$key_field]['priority'] = $priority;
}
return $new_fields;
}
// Account Edit Adresses: Reorder billing email and phone fields
add_filter( 'woocommerce_billing_fields', 'custom_billing_fields', 20, 1 );
function custom_billing_fields( $fields ) {
// Only on account pages
if( ! is_account_page() ) return $fields;
## ---- 2. Sort billing email and phone fields ---- ##
$fields['billing_email']['priority'] = 30;
$fields['billing_email']['class'] = array('form-row-first');
$fields['billing_phone']['priority'] = 40;
$fields['billing_phone']['class'] = array('form-row-last');
return $fields;
}
// Account Displayed Addresses : Remove 'address_2'
add_filter( 'woocommerce_my_account_my_address_formatted_address' , 'my_account_address_formatted_addresses', 20, 3 );
function my_account_address_formatted_addresses( $address, $customer_id, $address_type ) {
unset($address['address_2']); // remove Address 2
return $address;
}
代码位于活动子主题(或活动主题)的function.php文件中.经过测试和工作.
If you want to make that effective in checkout page too, you will have to remove this lines:
06001
In each function (2 times)…
内容总结
以上是互联网集市为您收集整理的php – 自定义Woocommerce 3中的我的帐户地址字段全部内容,希望文章能够帮你解决php – 自定义Woocommerce 3中的我的帐户地址字段所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。