I want to build a custom email template for the emails that are sent to customers when an order is placed. I will refer to customer-processing-order.php file. In it, there are two actions that display order details do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); and customer details do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );.

Digging deeper I see that in email-customer-details.php there is a foreach loop that outputs the contents of this function echo wp_kses_post( $field['value']. In email-addresses.php the address is displayed using this function <?php echo $order->get_formatted_billing_address(); ?>.

What I would like to do is to build an email template with each field parsed manually. How can I output the content of the functions above on a field by field basis? I want to mix fields in between them do display something like

Customer Name
Customer Address
Customer Phone
Custom checkout fields that I built
Customer shipping address 

Is there a way to display each field from Customer Details and Billing Address manually?

Thank you!


Probably the easiest way is to manually construct a new Billing address format by creating a copy of the WooCommerce email address template in /your-theme-driectory/woocommerce/emails/email-addresses.php by replacing the original echo $order->get_formatted_billing_address(); with for example:

$output  = '<strong>Customer Name: </strong>'.get_post_meta($order->id, '_billing_first_name', true).'<br>';
$output .= '<strong>Customer Last Name: </strong>'.get_post_meta($order->id, '_billing_last_name', true).'<br>';
$output .= '<strong>Company Name: </strong>'.get_post_meta($order->id, '_billing_company', true).'<br>';
$output .= '<strong>Country: </strong>'.WC()->countries->countries[get_post_meta($order->id, '_billing_country', true)].'<br>';
echo $output;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.