Using placeholders #
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_first_name] [shipping_last_name] [shipping_address_1] [shipping_address_2] [shipping_postcode] [shipping_city] [shipping_country]
Here’s a list of placeholders that you can use, excluding any custom fields:
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:
Billing fields | Shipping fields | Other data |
---|---|---|
[billing_address] | [shipping_address] | [order_total] |
[billing_first_name] | [shipping_first_name] | [order_weight] |
[billing_last_name] | [shipping_last_name] | [order_number] |
[billing_company] | [shipping_company] | [order_date] |
[billing_address_1] | [shipping_address_1] | [order_time] |
[billing_address_2] | [shipping_address_2] | [order_items] |
[billing_city] | [shipping_city] | [order_items_sku] |
[billing_postcode] | [shipping_postcode] | [order_items_full] |
[billing_country] | [shipping_country] | [shipping_method] |
[billing_country_code] | [shipping_country_code] | [shipping_notes] |
[billing_state] | [shipping_state] | [customer_note] |
[billing_state_code] | [shipping_state_code] | [date] |
[billing_email] | [total_qty] | |
[billing_phone] | [sku_list] | |
[qr_code] | ||
[site_title] | ||
[custom_field_name] | ||
[wc_order_barcode] |
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.
<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]
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 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' );