WooCommerce Get Order Data From the $order Object
The $order object (a WC_Order instance) is how you pull order data programmatically in WooCommerce — totals, items, customer details, billing/shipping, payment method, status, and custom meta. This covers the methods you’ll actually reach for when building a custom plugin, integration, or order-email customization, plus one change worth knowing about if you’re on a current WooCommerce install: High-Performance Order Storage (HPOS).
If you’ve worked with $product or $cart, $order works similarly but has its own quirks — particularly around metadata, which is covered below. When you only have an order ID rather than the object itself, get it with wc_get_order( $order_id ).
How to Get the $order Object
Before accessing any order data, you need to get the $order object. There are two common scenarios for this:
1.When you have the order ID
Use WooCommerce’s wc_get_order() function:
$order_id = 123; // Replace with your order ID
$order = wc_get_order( $order_id );
// Get Order ID and Key
$order->get_id();
$order->get_order_key();
// Get Order Totals
$order->get_formatted_order_total();
$order->get_cart_tax();
$order->get_currency();
$order->get_discount_tax();
$order->get_discount_to_display();
$order->get_discount_total();
$order->get_total_fees();
$order->get_formatted_line_subtotal();
$order->get_shipping_tax();
$order->get_shipping_total();
$order->get_subtotal();
$order->get_subtotal_to_display();
$order->get_tax_location();
$order->get_tax_totals();
$order->get_taxes();
$order->get_total();
$order->get_total_discount();
$order->get_total_tax();
$order->get_total_refunded();
$order->get_total_tax_refunded();
$order->get_total_shipping_refunded();
$order->get_item_count_refunded();
$order->get_total_qty_refunded();
$order->get_qty_refunded_for_item();
$order->get_total_refunded_for_item();
$order->get_tax_refunded_for_item();
$order->get_total_tax_refunded_by_rate_id();
$order->get_remaining_refund_amount();
// 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
$order->get_items_key();
$order->get_items_tax_classes();
$order->get_item_count();
$order->get_item_total();
$order->get_downloadable_items();
$order->get_coupon_codes();
// Get Order Lines
$order->get_line_subtotal();
$order->get_line_tax();
$order->get_line_total();
// Get Order Shipping
$order->get_shipping_method();
$order->get_shipping_methods();
$order->get_shipping_to_display();
// Get Order Dates
$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();
// Get Order User, Billing & Shipping Addresses
$order->get_customer_id();
$order->get_user_id();
$order->get_user();
$order->get_customer_ip_address();
$order->get_customer_user_agent();
$order->get_created_via();
$order->get_customer_note();
$order->get_address_prop();
$order->get_billing_first_name();
$order->get_billing_last_name();
$order->get_billing_company();
$order->get_billing_address_1();
$order->get_billing_address_2();
$order->get_billing_city();
$order->get_billing_state();
$order->get_billing_postcode();
$order->get_billing_country();
$order->get_billing_email();
$order->get_billing_phone();
$order->get_shipping_first_name();
$order->get_shipping_last_name();
$order->get_shipping_company();
$order->get_shipping_address_1();
$order->get_shipping_address_2();
$order->get_shipping_city();
$order->get_shipping_state();
$order->get_shipping_postcode();
$order->get_shipping_country();
$order->get_address();
$order->get_shipping_address_map_url();
$order->get_formatted_billing_full_name();
$order->get_formatted_shipping_full_name();
$order->get_formatted_billing_address();
$order->get_formatted_shipping_address();
// Get Order Payment Details
$order->get_payment_method();
$order->get_payment_method_title();
$order->get_transaction_id();
// Get Order URLs
$order->get_checkout_payment_url();
$order->get_checkout_order_received_url();
$order->get_cancel_order_url();
$order->get_cancel_order_url_raw();
$order->get_cancel_endpoint();
$order->get_view_order_url();
$order->get_edit_order_url();
// Get Order Status
$order->get_status();
// Get Thank You Page URL
$order->get_checkout_order_received_url();
2.Inside WooCommerce Hooks or Filters
If you’re using a WooCommerce hook like woocommerce_thankyou, the $order_id is passed as a parameter, and you can retrieve the $order object like this:
add_action( 'woocommerce_thankyou', 'my_custom_function', 10, 1 );
function my_custom_function( $order_id ) {
$order = wc_get_order( $order_id );
// Now you can access $order details
}
1. General Order Details
| Data | Method | Example Output |
|---|---|---|
| Order ID | $order->get_id() |
123 |
| Order Number | $order->get_order_number() |
#1005 |
| Order Status | $order->get_status() |
completed, pending, etc. |
| Order Date | $order->get_date_created() |
2024-01-01 12:00:00 |
| Order Modified Date | $order->get_date_modified() |
2024-01-02 14:00:00 |
| Currency | $order->get_currency() |
USD, EUR, etc. |
| Order Total | $order->get_total() |
150.00 |
| Order Subtotal | $order->get_subtotal() |
120.00 |
| Discount Total | $order->get_discount_total() |
10.00 |
| Total Tax | $order->get_total_tax() |
20.00 |
| Transaction ID | $order->get_transaction_id() |
txn_123456789 |
| Order Key | $order->get_order_key() |
wc_order_abcdef123456 |
2. Customer Information
| Data | Method | Example Output |
|---|---|---|
| Customer ID | $order->get_customer_id() |
1 (for registered users) |
| Billing First Name | $order->get_billing_first_name() |
John |
| Billing Last Name | $order->get_billing_last_name() |
Doe |
| Billing Full Name | $order->get_formatted_billing_full_name() |
John Doe |
| Billing Email | $order->get_billing_email() |
john.doe@example.com |
| Billing Phone | $order->get_billing_phone() |
+123456789 |
| Billing Address | $order->get_billing_address() |
123 Street, City |
| Shipping Full Name | $order->get_formatted_shipping_full_name() |
John Doe |
| Shipping Address | $order->get_formatted_shipping_address() |
123 Street, City |
3. Order Items
| Data | Method | Example Output |
|---|---|---|
| Items in the Order | $order->get_items() |
Array of items |
| Product Name | $item->get_name() |
T-Shirt |
| Product ID | $item->get_product_id() |
456 |
| Variation ID | $item->get_variation_id() |
457 (if a variation product) |
| Quantity | $item->get_quantity() |
2 |
| Line Subtotal | $item->get_subtotal() |
40.00 |
| Line Total | $item->get_total() |
80.00 |
| Tax for Line | $item->get_taxes() |
Tax array |
4. Payment Details
| Data | Method | Example Output |
|---|---|---|
| Payment Method | $order->get_payment_method() |
paypal, stripe, etc. |
| Payment Method Title | $order->get_payment_method_title() |
PayPal |
| Is Payment Complete? | $order->is_paid() |
true or false |
5. Shipping Details
Shipping Total : $order->get_shipping_total();
Shipping Tax : $order->get_shipping_tax();
Shipping Method : $order->get_shipping_method();
6. Coupons Used in the Order
To get the coupons applied to the order:
$coupons = $order->get_coupon_codes();
foreach ( $coupons as $coupon ) {
echo 'Coupon Code: ' . $coupon;
}
7. Metadata (Custom Fields)
If you’ve added custom metadata to the order:
$meta_data = $order->get_meta( '_custom_meta_key' );
echo 'Custom Meta: ' . $meta_data;
Iterating Over Items
To iterate over the order items, including product details:
$items = $order->get_items();
foreach ( $items as $item_id => $item ) {
$product = $item->get_product(); // WC_Product object
echo 'Product Name: ' . $item->get_name() . '<br>';
echo 'Quantity: ' . $item->get_quantity() . '<br>';
echo 'Price: ' . wc_price( $item->get_total() ) . '<br>';
}
Debugging: View All Order Data
To view everything available in the $order object for debugging:
echo '<pre>';
print_r( $order );
echo '</pre>';
Conclusion
The $order object in WooCommerce provides an extensive API to access all the order-related data you need. By leveraging the methods listed above, you can extract and use this data to customize order handling, reporting, and integrations.
A note on HPOS (High-Performance Order Storage)
Since WooCommerce 8.2, new stores default to HPOS, which stores order data in dedicated database tables instead of wp_posts/wp_postmeta. This doesn’t change anything in the code above — wc_get_order() and the WC_Order methods work identically either way, which is exactly the point of using the object API instead of querying the database directly.
It matters if you (or a plugin you’re maintaining) ever bypassed the object API with a direct $wpdb/get_post_meta() query against order data: as of WooCommerce 10.7 (April 2026), sync-on-read between the legacy tables and HPOS is disabled by default, so that kind of direct query can silently return stale or missing data on an HPOS store. Always obtain the order through wc_get_order() and confirm the result is a valid WC_Order before calling methods on it — and if you maintain older custom code that reads order data straight from wp_postmeta, that’s worth auditing.
A couple of practical reminders while you’re in this code: escape order data before printing it in HTML, never expose billing/address/payment fields to unauthorized visitors, and inside an order hook prefer the order object the hook already gives you over re-fetching it. For related guidance, see our WooCommerce order email guide.


