How to add a customer’s email and phone in the order email of WooCommerce

How to add customer email and phone in order email of WooCommerce

Sometimes a store manager finds it a bit difficult to see the customers’ contact information from the orders of WooCommerce. It’s a bit lengthy process since he has to open order management, then order details to view the information. To ease the process of finding customer information, we can add the customer’s email address and phone directly to the order email. This order email is sent to the store manager when a customer places an order on the website.

The default view

By default, the WooCommerce order email does not contain customers’ details. The default order emails look like below:

WooCommerce order email without customer contact details

Having a customer’s contact information in the email provides ease to store managers. The store manager can contact their customers easily in this case since they are getting contact details in the email itself.

Let’s do some code

In this article, we will be going to add a customer’s email and phone in the order email of WooCommerce. We need to write a hook that will modify the order email and will add customer contact information. Open functions.php of your child theme and add the following snippet:

<?php
// WooCommerce admin order email - add customer information
  function w3_order_email_customer_details( $order ) {
    $phone = $order->get_billing_phone();
    $email = $order->get_billing_email();

    echo '<h2>'._e( 'Customer details', 'woocommerce' ).'</h2>
         <ul>';
          if($phone) {
            echo '<li>
                <strong>'.wp_kses_post( 'Email address').':</strong> 
                <span class="text">'.wp_kses_post( $email ).'</span>
              </li>';
          }
          if($phone) {
            echo '<li>
                <strong>'.wp_kses_post( 'Phone').':</strong> 
                <span class="text">'.wp_kses_post( $phone ).'</span>
              </li>';
          }
      echo '</ul>';
  };

// add action
  add_action( 'woocommerce_email_customer_details', 'w3_order_email_customer_details', 10, 4 );
?>

The above action will work for WooCommerce version 2.5 or above.

Last but not least, in the above snippet, we have used the _e and wp_kses_post functions.

_e: used to display translated text if your website is multilingual.

wp_kses_post: sanitizes content for allowed HTML tags for post content.

The expected output

After adding the above snippet, the order email will look like the below:

woocommerce-order-email-with-customer-info
WooCommerce order email with customer contact details

Now, the store manager can easily get those details in the emails without logging into the wp-admin portal.

In the next article, we will see how to add the customers’ email and phone in the Order table of WordPress admin.

Related Posts