How to get customer details from an order in WooCommerce

In this tutorial, we will look at the different ways to get customer details from orders in WooCommerce.

You can get customer order details in WooCommerce in a few ways. One way is to go to the orders page and click on the order you want to view. This will take you to the order details page, where you can see all of the information about the order, including some customer details like the customer’s name, shipping address, and email. But if you want to access all of the customer details that your WooCommerce store has, there isn’t an out-of-the-box way to do it.

In this article, we will explore two ways to get customer details from order data. The first and main method covered in this article will be how to get customer details from the WooCommerce order object programmatically. For that, we first need access to the WooCommerce order object.

woocommerce customers details from order

How to get WooCommerce order data

If you have the order id available, you can access the order by using the wc_get_order WooCommerce function.

wc_get_order

wc_get_order is a function in WooCommerce that retrieves an order object based on the order ID, allowing developers to programmatically access and manipulate order-related data. It’s a crucial component for customizing and extending WooCommerce functionality through code.

You can use get methods from WC_Order  and WC_Abstract_Order  classes on the WC_Order object instance by using the $order_id like this:

Now that we have the order object, we have access to all the details associated with that specific order, including the customer details.

How to get customer order details programmatically from the WC_Order object

The WC_ Order object contains the regular WooCommerce orders extending the abstract order class. We have covered the WC_Order class in detail in our previous article. In this tutorial, we will focus only on getting the WooCommerce order details relevant to the customer.
 In the following example, we’ll see how to get the following details from a WooCommerce order:
  • get customer ID and user ID
  • get the user object
  • get the user roles
  • get the customer billing email
  • get customer phone number

 

As you can see, once you have access to the WooCommerce order object, you can get many customer details (and user info) related to that order. Let’s see how to get customer billing information and customer shipping information from the order data:

The code above demonstrates how to create an order object using the WooCommerce wc_get_order function. Once you have created the object, you can use different methods to get information about the user, such as their name and address.

Unlock the Full Potential of Your WooCommerce Customer Data

How to use the WC_Order get_data() method

You can also use the get_data() method to get an unprotected data array from Order metadata like:

 

How to get customer details from an order without a code

If you want to get all the customer details based on a particular WooCommerce order but are not looking for a coding solution, you can do it with the help of Users Insights. Suppose you have the plugin installed and active on your WooCommerce store. In that case, Users Insights will create an advanced WooCommerce customer profile that has all the available customer details in one place. The plugin also automatically links WooCommerce order details with the WooCommerce customer details. Additionally, it adds a link to every ordered item in WooCommerce to the corresponding WooCommerce customer profile. To find the customer details associated with a specific order, you must first navigate the WooCommerce -> Orders list in your WordPress dashboard.

woocommerce customer details

Once you find the specific order you are looking for, click and open the order page.

woocommerce customer details from order

You will see a “Users Insights Profile →” link under the customer’s name. This links to the WooCommerce customer profile page of the customer who has purchased the order, and from there, you can get all the customer details you might need.

woocommerce customer get details