Overview
TheWC_Order class represents a customer order in WooCommerce. It provides methods to manage order data, items, totals, status, and customer information.
Always use
wc_get_order() to retrieve orders rather than creating WC_Order objects directly.Getting an Order
Order Data Structure
TheWC_Order class stores comprehensive order data:
Order Information
string
Order status:
pending, processing, on-hold, completed, cancelled, refunded, failedstring
Currency code (e.g.,
USD, EUR)WC_DateTime
Date order was created
WC_DateTime
Date order was last modified
WC_DateTime|null
Date order was completed
WC_DateTime|null
Date order was paid
Customer Information
int
Customer user ID (0 for guests)
string
Customer IP address
string
Customer browser user agent
string
Customer-provided order notes
Billing Address
array
Billing address fields:
first_namelast_namecompanyaddress_1address_2citystatepostcodecountryemailphone
Shipping Address
array
Shipping address fields (same structure as billing, minus email/phone)
Payment Information
string
Payment gateway ID
string
Payment method display name
string
Payment transaction ID from gateway
Order Totals
string
Order grand total
string
Total discount amount
string
Tax on discounts
string
Shipping cost
string
Tax on shipping
string
Cart tax amount
string
Total tax amount
Common Methods
Getting Order Data
Setting Order Data
Creating a New Order
Order Status Management
Getting Order Status
Updating Order Status
Payment Complete
Working with Order Items
Getting Order Items
Adding Items
Removing Items
Order Totals
Calculating Totals
Getting Totals
Order Notes
Adding Notes
Getting Notes
Refunds
Creating a Refund
Getting Refunds
Metadata
Hooks
Order Status Hooks
Order Save Hooks
Best Practices
Use wc_get_order()
Always use
wc_get_order() instead of direct instantiation.Save Changes
Call
$order->save() after modifications.Recalculate Totals
Call
$order->calculate_totals() after adding/removing items.Use update_status()
Use
update_status() instead of setting status directly.