Customizing WooCommerce Shipping Address in Order Emails

In a recent Business Bloomer Club Slack thread, a WooCommerce user asked about customizing the shipping address displayed in the order emails.

Specifically, they wanted to modify the address shown in the woocommerce_email_customer_details template. Here’s a guide on how to approach this customization.

Solution: Use the woocommerce_order_get_formatted_shipping_address Filter

The woocommerce_order_get_formatted_shipping_address filter allows you to modify the formatted shipping address for WooCommerce order emails. This filter can be applied to adjust the address output without altering WooCommerce’s core files.

  1. Add the Filter in functions.php:
  • Add this snippet to your theme’s functions.php file or in a custom plugin to change the shipping address format.
   add_filter( 'woocommerce_order_get_formatted_shipping_address', 'custom_shipping_address_format', 10, 3 );

   function custom_shipping_address_format( $address, $raw_address, $order ) {
       // Customize the $address array as needed
       $address = $address ? $address : 'Custom Shipping Address Here';
       return $address;
   }
  1. Customize the $address Array:
  • Modify elements of $address to suit your requirements. For example, you can add notes, change the format, or replace specific fields based on your store’s needs.
  1. Test the Email Output:
  • Complete a test order to verify that the customized shipping address displays correctly in order emails.

Alternative: Overriding email-addresses.php

If you need more granular control over the email layout, you can override the email-addresses.php template.

  1. Copy the Template:
  • Copy woocommerce/templates/emails/email-addresses.php to your theme’s WooCommerce folder at your-theme/woocommerce/emails/email-addresses.php.
  1. Customize the Address Output:
  • Within the copied template, modify the structure or add conditional statements to customize how the shipping address displays.

Conclusion

Using the woocommerce_order_get_formatted_shipping_address filter provides a quick way to customize the shipping address in WooCommerce emails, while overriding email-addresses.php offers more control over the entire email layout. Either approach enables you to tailor WooCommerce order emails to meet your specific requirements.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *