WooCommerceWordPress

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

0
1k
2019 / 10 / 08

Sometimes a store manager finds a bit difficult to find customer’s contact information from the order management of WooCommerce. To make them easy to find customer information, we can add the customer’s email address and phone in the order email. The order email is sent to the store manager when a customer placed an order on the website.

For example, the following screenshot shows customer details added in the order notification email.

Having a customer’s contact information in the email makes it easy for store managers to contact them easily.

We need to write a hook that will modify order email and 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 woo_order_email_customer_details( $order ) {
$phone= $order->get_billing_phone();
$email=$order->get_billing_email();
?>
 <h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
 <ul>
   <li><strong><?php echo wp_kses_post( 'Email address'); ?>:</strong> <span class="text"><?php echo wp_kses_post( $email ); ?></span></li>
<?php if($phone) { ?>
     <li><strong><?php echo wp_kses_post( 'Phone'); ?>:</strong> <span class="text"><?php echo wp_kses_post( $phone ); ?></span></li>
  <?php } ?>
 </ul>
<?php
};

add_action( 'woocommerce_email_customer_details', 'woo_order_email_customer_details', 10, 4 );

Note: Please open and close PHP tags according to your functions.php of the child theme.

The above snippet will add the customer’s email and phone in the order email.

Now, the store managers can easily get customer’s contact information with the order email.

 

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks