By implementing this customization, store owners gain direct access to crucial customer details right from their inbox. Store owners can discern quick details like whether the order is from a returning customer or a new customer, the total order count, and the status of the current order. This eliminates the need for admins to navigate through the dashboard to search for each aspects of information but directly view it in the new order admin emails.
Solution: Display Customer Details in Admin New Order Emails
The code snippet will customize the content of the “new_order” admin email notification in WooCommerce by displaying information about the customer, including whether they are new or returning, the number of purchases they have made, and the status of the current order.
function ts_action_woocommerce_email_order_details( $order, $sent_to_admin, $plain_text, $email ) { // Target specific email notification if ( $email->id == 'new_order' ) { // Get email $customer_email = $order->get_billing_email(); // NOT empty if ( ! empty ( $customer_email ) ) { // Get orders from customer by email and statuses $orders_by_customer_email = wc_get_orders( array( 'customer' => $customer_email, 'limit' => -1, 'return' => 'ids' )); // When new customer if ( count( $orders_by_customer_email ) == 1 ) { $customer = __( 'new', 'woocommerce' ); } else { $customer = __( 'returning', 'woocommerce' ); } // Get order status $order_status = $order->get_status(); // Output echo '<p style="color:red;font-size:14px;">' . sprintf( __( 'Customer: %s, number of purchases: %d, order status: %s', 'woocommerce' ), $customer, count( $orders_by_customer_email ), $order_status ) . '</p>'; } } } add_action( 'woocommerce_email_order_details', 'ts_action_woocommerce_email_order_details', 10, 4 );
Output
The code first captures the customer’s email associated with the order. If the customer’s email isn’t empty, it proceeds to retrieve the total number of orders linked to that email address. If only one order is found, the customer is identified as new; otherwise, they’re recognized as a returning customer. Additionally, the code fetches the status of the current order and showcases it alongside the customer’s status and order count in the admin’s new order email notification.
If the customer has made more than one purchase previously, the code identifies them as a returning customer. Their total order counts along with order status is also displayed in admin new order email notifications.
Similarly, want to retrieve the coupons used by customers in admin new order emails? It’s simple than you think! Check out our post on how to add coupon details table in the WooCommerce new order email.