WooCommerce has various address format based on the input countries. You can add any custom address format by applying condition for specific country. Its easy to implement by adding below code in your WordPress child theme functions.php file.
Create WooCommerce Custom Address Format
Add this code in function.php file of your child theme. You can mention any country code instead of ‘CA’. In this format \n is used to create a new line.
1 2 3 4 5 6 7 |
add_filter( 'woocommerce_localisation_address_formats', 'custom_address_formats', 20 ); function custom_address_formats( $formats ) { $formats[ 'CA' ] = "{first_name} {last_name}\n{address_1}\n{address_2}\n{city} {state}\n {postcode} \n{country}"; return $formats; } |
WooCommerce Address format Tags
These tags are available in WooCommerce to construct an formatted address.
{address_1} — First line of address.
{address_2} — Second line of address.
{street_number} — Separate street number if {address_1} does not mentioned
{postcode}
{city}
{state}
{state_code}
{country}
You can find all countries address format in WooCommerce in get_address_formats() method. This method is located under \woocommerce\includes\class-wc-countries.php file.