Changing the address format

Using placeholders (Professional extension) #

With WooCommerce PDF Invoices & Packing Slips Professional, you can override the default WooCommerce address format (which is formatted using the standard of the country of the address) by building your own address format using placeholders.

Here’s a simple example:

{{shipping_first_name}} {{shipping_last_name}}
{{shipping_postcode}} {{shipping_city}}

In addition to these default address fields, you can also display custom fields from the order, like {{vat_number}} if you are using WooCommerce EU VAT Numbers plugin. Simply put the custom field name between double accolades (curly brackets), minus a leading underscore if it has one: so a custom field with the name _delivery_date would become {{delivery_date}}. More information on custom fields: Displaying a custom field

Here’s a list of placeholders that you can use, excluding any custom fields:

Shipping addressBilling addressMisc other

Using HTML #

With these placeholders, you not only have full control over the contents of the address, but you can also use HTML to format each element separately.

<b>{{shipping_first_name}} {{shipping_last_name}}</b>
{{shipping_postcode}} {{shipping_city}}

You can even add images, using the HTML <img> tag, like a logo above the address:

<img style="width: 3cm;" src="" alt="" />

WooCommerce wide #

This is recommended for experienced users only, if you want full control over the address format per country, woocommerce wide.

WooCommerce already preformats the address for you if you use the [shipping_address] or [billing_address] tag. One thing this does is that it omits the country name if it’s the same as the shop base country, and it also uses specific per-country formats. If you want to preserve the per-country format but just change the format for a specific country, you can do this WooCommerce wide (emails, backend, and also the address labels) with a filter, woocommerce_localisation_address_formats. Read this if you haven’t worked with filters or functions.php before: How to use filters.

Here’s an example that changes the address format for the US, putting the company name before the customer name:

add_filter( 'woocommerce_localisation_address_formats', 'woocommerce_custom_address_format', 20 );
function woocommerce_custom_address_format( $formats ) {
    $formats[ 'US' ]  = "{company}\n{name}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}";
    return $formats;

Some pointers here:

  • \n stands for a line break
  • US is the country code
  • You can use the following placeholders:
    • {first_name}
    • {last_name}
    • {name}
    • {company}
    • {address_1}
    • {address_2}
    • {city}
    • {state}
    • {state_code}
    • {postcode}
    • {country}
  • and their uppercase versions:
    • {first_name_upper}
    • {last_name_upper}
    • {name_upper}
    • {company_upper}
    • {address_1_upper}
    • {address_2_upper}
    • {city_upper}
    • {state_upper}
    • {postcode_upper}
    • {country_upper}

If you want to print the country name even for domestic addresses, you can use another filter, woocommerce_formatted_address_force_country_display:

add_filter( 'woocommerce_formatted_address_force_country_display', '__return_true' );