简体   繁体   中英

Change the order of admin billing address fields in WooCommerce orders

I have problem with woocommerce order in admin I want the billing_address_2 show at the end of the page as exmple bellow.

can any one please help me.

在此处输入图片说明

The core file that is responsible to displayinng that fields is located in WooCommerce plugin under: includes/admin/meta-boxes/class-wc-meta-box-order-data.php .

The only available and efficient hook is: woocommerce_admin_shipping_fields .

But you will only be able to change the admin billing fields order using something like:

add_filter( 'woocommerce_admin_billing_fields' , 'change_order_admin_billing_fields' );
function change_order_admin_billing_fields( $fields ) {
    global $the_order;

    $address_2 = $fields['address_2'];

    unset($fields['address_2']);

    $fields['address_2'] = $address_2;

    return $fields;
}

Which will give you something like:

在此处输入图片说明

So as you can see you will not get the billing address_2 field to be displayed after the transaction ID as you wish, but only under the billing phone field.


Addition - Showing the billing_address_2 field before billing_country field :

add_filter( 'woocommerce_admin_billing_fields' , 'change_order_admin_billing_fields' );
function change_order_admin_billing_fields( $fields ) {
    global $the_order;

    $sorted_fields = [];
    $address_2 = $fields['address_2'];
    unset($fields['address_2']);

    foreach ( $fields as $key => $values ) {
        if( $key === 'country' ) {
            $sorted_fields['address_2'] = $address_2;
        }
        $sorted_fields[$key] = $values;
    }

    return $sorted_fields;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM