Enhancing Order Details: Adding Customer Email and Phone to the WordPress Admin Order Table

How to add the customers’ email and phone in the Order table of WordPress admin

In the world of online selling, it’s important to make things easy for both sellers and buyers. One way to do that is by upgrading how you handle orders. This guide will show you how to make things smoother by adding customer email and phone details to the Order table in WordPress admin. Let’s dive into simple steps to make your order management better.

Introduction: Why Customer Info Matters

Sometimes a store manager finds it a bit difficult to find customer email and phone from the orders of WooCommerce.  It’s a bit lengthy process since he has to open order management, and then order details to view the information. To ease the process of finding customer information, we can add the customer email and phone directly to the orders. This is the order table of the WordPress admin portal.

Knowing the Order Table

To make our changes, we need to know where and how to fit in customer details in the Order table. Let’s look at the structure of the Order table in WordPress admin. By default, the WooCommerce order table does not contain customer details. It looks like the following screenshot:

woocommerce-orders-list-without-customer email and phone
WooCommerce orders list without customer information

What we are expecting?

Here we wanted to show the customers’ email and phone in the orders table to the WordPress admins’ orders list. What we are trying to achieve is displayed in the following screenshot:

woocommerce-orders-list-with- customer email and phone
WooCommerce orders list with customer information

The store manager will see the customer email and phone directly with the order, under the Order column.

Implementation no. 1: customer email and phone

To add the above-mentioned feature, let’s add the following code in the functions.php of your child theme.

<?php
// add customer email and phone to order in backend - order management
	function w3_customer_information_order_column( $column, $post_id ) {
	    if ( $column == 'order_number' ){
	        global $the_order;

	        if( $customer_phone = $the_order->get_billing_phone() ){
	            echo '<p><a href="tel:'.$customer_phone.'"><span class="dashicons dashicons-phone"></span> '.$customer_phone.'</a></strong></p>';
	        }

	        if( $customer_email = $the_order->get_billing_email() ){
	            echo '<p><a href="mailto:'.$customer_email.'"><span class="dashicons dashicons-email"></span> '.$customer_email.'</a></strong></p>';
	        }
	    }
	}

	add_action( 'manage_shop_order_posts_custom_column' , 'w3_customer_information_order_column', 50, 2 );
?>

Note: Don’t forget to check the opening and closing tags of PHP.

Implementation no. 2: customer email and phone using hooks

Most of the magic in WordPress happens in the functions.php file of the child theme. Here, we’ll use filters and hooks functions to get and show customer email and phone details in the Order table.

Getting Customer Info

Our first step is to create a function that fetches the customer email and phone from each order.

// Function to get customer email and phone
function get_customer_contact_info($order_id) {
    $customer_data = array(
        'email' => get_post_meta($order_id, '_billing_email', true),
        'phone' => get_post_meta($order_id, '_billing_phone', true),
    );
    return $customer_data;
}

Showing Info in the Order Table

Now, we’ll make sure this information appears in the Order table.

// Function to add columns to the Order table
function add_customer_columns($columns) {
    $columns['customer_email'] = 'Customer Email';
    $columns['customer_phone'] = 'Customer Phone';
    return $columns;
}

// Function to put data in the new columns
function populate_customer_columns($column, $post_id) {
    if ($column === 'customer_email' || $column === 'customer_phone') {
        $customer_info = get_customer_contact_info($post_id);
        echo esc_html($customer_info[$column]);
    }
}

Dashicons

To make it more interactive, we have used dash-icons.

Dash-icon is the official icon of WordPress. The syntax for using dash icons is:

<span class="dashicons dashicons-email"></span>

Click here to access the cheat sheet for dash icons.

Testing and Checking: Making Sure It Works

Before you make these changes live, it’s important to test them out. We’ll check to make sure customer email and phone details smoothly show up in the Order table without causing any issues.

Conclusion: Better Order Management with Customer Details

Well done! You’ve successfully improved your WordPress admin Order table by adding customer email and phone details. This small change makes your order system more efficient and customer-friendly. Feel free to explore more ways to make your order system fit your online store better.

By adding customer details to the Order table, you’re not just handling orders; you’re creating a friendlier and more personalized online shopping experience. Enjoy making these improvements!

In the next article, we will see how to add a customer’s email and phone in the order email of WooCommerce.

Related Posts