Nicola Mustone

Happiness Lead @ Automattic



How to Customise the Address Format in WooCommerce

Each country has a different address format, for example, U.S. uses the abbreviated state name, while Australia usually shows the full state name.

These are not rules set in stone though and they can always be changed. How? Via custom code of course!

Before implementing any code changes, always ensure your site is backed up. This will help you restore things in case of unforeseen errors. I recommend using Jetpack Backup for real-time backups and one-click restores.

Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

<?php
add_filter( 'woocommerce_localisation_address_formats', 'change_us_address_format' );
function change_us_address_format( $formats ) {
$formats['US'] = "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state} {postcode}\n{country}";
return $formats;
}
view raw functions.php hosted with ❤ by GitHub

This code changes the address format for the United States, using the full state name instead of the state code so that an address like:

Nicola Mustone
937 South Green St.
Fresno, CA 93722

will become:

Nicola Mustone
937 South Green St.
Fresno, California 93722

Address format options

In the code, you can see some placeholders like {name}  or {state}, but there are many of these that you can use in your custom format.

Here is a complete list:

  • {first_name}
  • {last_name}
  • {name}
  • {company}
  • {address_1}
  • {address_2}
  • {city}
  • {state}
  • {postcode}
  • {country}
  • {first_name_upper}
  • {last_name_upper}
  • {name_upper}
  • {company_upper}
  • {address_1_upper}
  • {address_2_upper}
  • {city_upper}
  • {state_upper}
  • {state_code}
  • {postcode_upper}
  • {country_upper}
Advertisements

Subscribe to This Blog

Receive new articles from this blog directly in your inbox! No spam guaranteed!

Join 651 other subscribers

Contribute to Improving This Blog

Did you enjoy this article? Was it helpful? Contribute to help me write more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

€5.00
€15.00
€100.00
€5.00
€15.00
€100.00
€5.00
€15.00
€100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly
Advertisements

More Posts That You Might Like…


2 responses to “How to Customise the Address Format in WooCommerce”

  1. working good i need to check how to setup that in woocommerce so i can finish it

  2. Thanks for your useful post. Do you have any plugin recommendations? I just want to customize the address format with some simple clicks, instead of entering this code. 🙂

Leave a Reply

Advertisements

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 651 other subscribers

About The Author

Hi, I’m Nico! Support Lead at Automattic, championing WordPress.com & WooCommerce. Off-duty, I’m at Elemental Beacon, leading epic D&D adventures. Let’s connect, whether it’s about WordPress or a quest!

Advertisements

Don't Miss a Thing!

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Join 651 other subscribers

Continue Reading

%d bloggers like this: