Home › Forums › Themes Support › Claue › Reordering the Address fields
- This topic has 3 replies, 2 voices, and was last updated 6 years, 2 months ago by Harry.
-
AuthorPosts
-
-
October 21, 2018 at 10:42 pm #25883
Hi Harry,
As you know in the checkout page, the customer selects the state and then city and then the address field.
But in the billing address in the dashboard,
domain.com/my-account/edit-address/billing
, the state and the city is afterthe address.
Can you please help me to reorder the fields.
I found this function which is working, but I don’t have the knowledge to reorder the 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; }
Regards.
Rahim Vaziri
CEO & Founder at Look.ir -
October 22, 2018 at 12:07 pm #25888
Hi Rahim,
Please change code
sorted_fields = array('first_name','last_name','company','address_1','country','postcode','city','state');
to
$sorted_fields = array('first_name','last_name','company','country','state','city','postcode','address_1');
Regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio -
October 23, 2018 at 3:07 pm #25932
Hi Harry,
After editing the code as you said the places of the state and city where fine, but phone and email were not at the end of the line.
I changed the priority to “0” and now it’s fine.
Is it ok to make them 0?
## ---- 2. Sort billing email and phone fields ---- ## $fields['billing_email']['priority'] = 0; $fields['billing_email']['class'] = array('form-row-first'); $fields['billing_phone']['priority'] = 0; $fields['billing_phone']['class'] = array('form-row-last'); return $fields; }
Regards.
Rahim Vaziri
CEO & Founder at Look.ir -
October 23, 2018 at 5:13 pm #25941
It no problem, change it when it work for you.
Regards
Harry
Premium Wordpress themes and plugins, Best WooCommerce theme https://themeforest.net/user/janstudio/portfolio?ref=janstudio
-
-
AuthorPosts
You must be logged in to reply to this topic.