Formatting the address

By default, the WooCommerce Print Address labels plugin uses the address as formatted by WooCommerce, which is different for each country. You can override this behavior by building your own address format using placeholders.

Here’s a simple example:

[shipping_company]
[shipping_first_name] [shipping_last_name]
[shipping_address_1]
[shipping_address_2]
[shipping_postcode] [shipping_city]
[shipping_country]

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 brackets, minus a leading underscore if it has one: so a custom field with the name _delivery_date would become [delivery_date].

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

Shipping address Billing address Misc other
[shipping_address]
[shipping_first_name]
[shipping_last_name]
[shipping_company]
[shipping_address_1]
[shipping_address_2]
[shipping_city]
[shipping_postcode]
[shipping_state]
[shipping_state_code]
[shipping_country]
[shipping_country_code]
[billing_address]
[billing_first_name]
[billing_last_name]
[billing_company]
[billing_address_1]
[billing_address_2]
[billing_city]
[billing_postcode]
[billing_state]
[billing_state_code]
[billing_country]
[billing_country_code]
[billing_email]
[billing_phone]
[order_total]
[shipping_method]
[customer_note]
[order_number]
[order_date]
[date]
[order_items]
[qr_code]
[custom_field_name]

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.

<span style="font-size: 10pt;">[order_number]</span>
 
<b>[shipping_company]</b>
<b>[shipping_first_name] [shipping_last_name]</b>
[shipping_address_1]
[shipping_address_2]
[shipping_postcode] [shipping_city]
[shipping_country]

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

<img style="width: 3cm;" src="http://www.yoursite.com/logo.png" alt="" />
[shipping_address]

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 linebreak
  • 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' );