Notice: Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.0.) in /home/codexcoach/htdocs/ on line 5857

How to Get WooCommerce Order Details From $order Object (A Guide)

How to Get WooCommerce Order Details From $order Object

This guide is all about understanding the basics of WooCommerce: the Order object. It’s like a treasure trove filled with everything from a customer’s shopping journey on your online store to their personal details to payments, shipping and the items they purchased.

We’ll learn how to use this wealth of information using both WooCommerce’s ready-made features and some custom code. By the end, you’ll know how to highlight key order details like order ID, key, total, and URL, making it easier to navigate and understand.

How to Get Customer Details From an Order in WooCommerce?

In this guide, we will learn how to get customer details from orders in WooCommerce.

To learn more about your customers’ orders in WooCommerce, you can visit the Orders page. Click on the order you are interested in and you will see details like customer name, address, and email. However it is not easy to get all the customer information from your WooCommerce store.

We will cover two ways to get customer details from orders. The main focus will be on getting this information programmatically from the WooCommerce Order object. First, we need to access this Order object.

1. You Have Access to $order Variable

// Get Order ID and Key
// Get Order Totals
// Get and Loop Over Order Items
foreach ( $order->get_items() as $item_id => $item ) {
   $product_id = $item->get_product_id();
   $variation_id = $item->get_variation_id();
   $product = $item->get_product(); // see link above to get $product info
   $product_name = $item->get_name();
   $quantity = $item->get_quantity();
   $subtotal = $item->get_subtotal();
   $total = $item->get_total();
   $tax = $item->get_subtotal_tax();
   $tax_class = $item->get_tax_class();
   $tax_status = $item->get_tax_status();
   $allmeta = $item->get_meta_data();
   $somemeta = $item->get_meta( '_whatever', true );
   $item_type = $item->get_type(); // e.g. "line_item", "fee"
// Other Secondary Items Stuff
// Get Order Lines
// Get Order Shipping
// Get Order Dates
// Get Order User, Billing & Shipping Addresses
// Get Order Payment Details
// Get Order URLs
// Get Order Status
// Get Thank You Page URL

2. You Have Access to $order_id Variable

// Get $order object from order ID
$order = wc_get_order( $order_id );
// Now you have access to (see above)...
if ( $order ) {
   $order->get_formatted_order_total( );
   // etc.
   // etc.

3. You Have Access to $email Variable

// Get $order object from $email
$order = $email->object;
// Now you have access to (see above)...
if ( $order ) {
   $order->get_formatted_order_total( );
   // etc.
   // etc.

How useful was this blog?

Click on a star to rate it!

Average rating 4.7 / 5. Vote count: 1654

No votes so far! Be the first to rate this blog.

By Subhash Katakiya

Hey Guys, My Self Subhash Katakiya. I am a resident of Gujarat. I have 2+ years of experience in full-stack web development. Currently, I am working in CodexCoach Company. In particular, I specialize in WooCommerce, plugins, and themes. So, read my blogs and learn full-stack web development skills with my guide.

Leave a comment

Your email address will not be published. Required fields are marked *