// 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;
}

參考網站:https://stackoverflow.com/questions/49641316/customizing-my-account-addresses-fields-in-woocommerce-3

別人寫的程式
主要是改變 我的帳號 > 地址 > 帳單地址&運送地址 的表格排序
這段碼放於function.php裡面

接下來由於 外國人的姓名用法與台灣人不同

所以即便更改了順序 兩個欄位卻連在一起

$sorted_fields = array('last_name','first_name','company','address_1','country','state','city','postcode');

$sorted_fields裡面是個欄位的順序

所以如果有需要更改欄位順序的話 變更這一段即可

對應最上面 要放在function裡面的程式碼

要去改變他們的class

不然姓氏 是last 名字是first 所以才會相連

woocommerce表單 改變的地方在

wp-content/plugins/woocommerce/includes/class-wc-countries.php

大約600多行

把First name的form-row-first 與 Last name的form-row-last對調

就像下面這樣 就完成囉

改完之後的呈現

最後修改日期: 2021 年 4 月 15 日

作者