How to Change the Default Address Format

The AudioTheme plugin will attempt to format some addresses automatically based on the country of the address, but it can only do so if the country is stored in a format that is easily recognized.

Using ISO 3166-1 alpha-2 codes for countries is the only sure method. If you’re not using the a country code, the plugin attempts to match the country name, but that only works when the name matches exactly (punctuation and all). When translating or using a more informal name, a match won’t be made.

If that functionality doesn’t work for you and you want to change the default address format, we’ve provided a couple of ways to do so:

Translating the Address Format

If you’ve translated the AudioTheme plugin using the POT file or a plugin like Loco Translate, you can update the address format. Search for the string that looks like this:

{name}\n{address}\n{city}, {state} {postal_code}\n{country}\n{phone}

You can rearrange the placeholders in that string to adjust the format.

Translate with Say what?

The Say what? plugin allows you to translate individual strings on a website. After you’ve installed Say what?, go to Tools → Text changes in your admin panel and add a new entry with the following values:

Original string: {name}\n{address}\n{city}, {state} {postal_code}\n{country}\n{phone}
Text domain: audiotheme
Text context: (leave this one blank)
Replacement string: (enter your replacement)

Filter the Template

The address format can be filtered in a child theme or custom plugin using a snippet like below:

add_filter( 'audiotheme_address_format_template', function( $template, $country_code, $country ) {
	return "{name}\n{address}\n{city}, {state} {postal_code}\n{country}\n{phone}";
}, 10, 3 );