在Woocommerce 3中自定义我的帐户地址字段

判断

我想删除模板form-edit-addresses.php中的表单字段billing_adress_2。

要完成,可以像这样对表单字段重新排序:


名-姓

电子邮件-电话

公司

地址1

邮编


此更改我只想将其应用于页面(模板)form-edit-addresses.php

任何帮助表示赞赏

LoicTheAztec

在“我的帐户”>“地址”部分中,以下挂钩的功能将:

  • 删除“地址2”的帐单和送货字段
  • 重新订购帐单和送货地址字段
  • 重新排序帐单电子邮件和电话字段(在名字和姓氏之后)
  • 从显示中删除“地址2”

您忘记了可以在$ sorted_fields数组中轻松重新排序“国家”字段...

编码:

// 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文件中。经过测试和工作。

如果您也想在结帐页面上使其有效,则必须删除以下行:

// Only on account pages
if( ! is_account_page() ) return $fields;

在每个功能中(2次) ……

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

隐藏自定义结帐字段,使其不显示在WooCommerce我的帐户编辑地址中

在Woocommerce编辑帐户页面中添加自定义字段

每个客户只能在“我的帐户”>“在WooCommerce中编辑帐户”上编辑一次自定义字段

在 Woocommerce 3 中显示自定义帐户菜单项的自定义内容

发送带有保存在Woocommerce 3中的其他帐户字段值的自定义电子邮件

Woocommerce 3中的自定义结帐字段验证

在Woocommerce编辑个人资料“我的帐户”页面中提供自定义注册字段

在 WooCommerce 中隐藏自定义字段

在WooCommerce我的帐户自定义菜单项内容中定义用户变量

在Woocommerce编辑帐户页面中添加其他自定义字段

绕过 WooCommerce 我的帐户登录以进行自定义登录

如何自定义woocommerce“我的帐户”页面?

在商店地址部分的Woocommerce常规设置中添加自定义字段

在 WooCommerce 管理订单编辑页面中显示帐单地址之间的自定义字段

如何在 Woocommerce 我的帐户侧边栏中添加新的自定义标题?

在WooCommerce中设置“我的帐户”自定义项目终结点标题

在Woocommerce中每页自定义我的帐户订单列表帖子

为Woocommerce中的特定用户角色自定义我的帐户新菜单项

在Woocommerce中获取作为“自定义我的帐户”页面内容分页的未购买商品

在 WooCommerce 我的帐户订单自定义列中添加“支付订单”按钮

在 WooCommerce 我的帐户中更改标题自定义“查看订单”端点

Woocommerce 3中的自定义模板

如何在 WooCommerce“我的帐户”页面上对自定义字段重新排序或添加优先级

在Woocommerce 3中将自定义结帐字段添加为“订购自定义元数据”

在WooCommerce快速订单预览中显示自定义字段

结帐页面WooCommerce中的自定义交付字段

在woocommerce结帐页面自定义字段中添加日期

订单编辑页面中的WooCommerce自定义字段

从WooCommerce的自定义结帐计费字段中获取价值