Guide: WooCommerce Order Data

WooCommerce stores order records in the posts table and its associated data in the postmeta table by default. To access and update order data, WooCommerce offers a number of helper methods.

Order Object

To use WooCommerce methods, you’ll need an instance of the WC_Order object.

Use `wc_get_order` to get an instance of the order. Example:

// Get order ID #123
$order = wc_get_order( 123 );

Basic Order Properties

// Get Order ID

// Get Order Key

Get custom meta data

WooCommerce has built-in methods for accessing most data it sets (which I’ll list below), but if need to access custom meta data you’ve added or another WooCommerce extension has added, get_meta is the method for you.

$order->get_meta( $key );

Let’s say you want to add gift note data to an order:

$order->update_meta_data( 'gift_note', 'Hi Mom!' );

After saving the meta data, you would access it with:

$order->get_meta( 'gift_note' );

Order Status

// Get Order Status

You can get a list of all valid order statuses using `wc_get_order_statuses()`:


// Output
["wc-pending"] => "Pending payment"
["wc-processing"] => "Processing"
["wc-on-hold"]=> "On hold"
["wc-completed"]=> "Completed"
["wc-cancelled"]=> "Cancelled"
["wc-refunded"]=> "Refunded"
["wc-failed"]=> "Failed"

To set an order status:

$order->set_status( 'completed' );

The “wc-” prefix is detected automatically when setting a status. So `$order->set_status( ‘completed’ );` is exactly the same as `$order->set_status( ‘wc-completed’ );`.

Order Pricing and Totals

Methods for getting prices and totals from the order.


Order Dates


If you have third-party services that pull from your WooCommerce API, it’s often useful to update the modified date of an order after modifing any data. Here’s how to do that:

$order->set_date_modified( time() );

Other order date setters:

// Date should be mysql format.
$timestamp = time();

$order->set_date_paid( $timestamp );
$order->set_date_completed( $timestamp );

Order Address and User Information


To update address and user data:

// Billing Address
set_billing_first_name( $string )
set_billing_last_name( $string )
set_billing_company( $string )
set_billing_address_1( $string );
set_billing_address_2( $string );
set_billing_city( $string );
set_billing_state( $string );
set_billing_postcode( $string );
set_billing_country( $string );
set_billing_phone( $string );

// Shipping Address
set_shipping_first_name( $string );
set_shipping_last_name( $string );
set_shipping_company( $string );
set_shipping_address_2( $string );
set_shipping_city( $string );
set_shipping_state( $string );
set_shipping_postcode( $string );
set_shipping_country( $string );
set_shipping_phone( $string );

// Order customer
set_customer_id( $id )
set_billing_email( $email );

// If the order has user (customer_id), update billing email
// to use the email for that customer (user).

Shipping Methods


Payment Methods


Additional Documentation

If you need more information about how any of these methods work, the WooCommerce source code is one of the best places to look. You can find all the methods listed here and many more in the WC_Abstract_Order class.

Leave a Reply