Migrate WooCommerce orders to High-Performance Order Storage (HPOS)
High-Performance Order Storage moves WooCommerce orders out of wp_posts and wp_postmeta into their own tables: wc_orders, wc_order_addresses, wc_order_operational_data and wc_orders_meta. It appeared as an opt-in feature in WooCommerce 7.1, and with WooCommerce 8.2 (October 2023) it becomes the default for new stores. The reason is performance: in the post tables, order queries need many joins through a wp_postmeta table shared with products, pages and attachments, while the new tables are designed and indexed for orders (status, customer, date, total).
Problem: The order list and order search of a store with tens of thousands of orders are slow, and custom code that reads orders with get_post_meta() will stop seeing the data after the switch.
Solution: Make your code use the WooCommerce order API instead of post functions, declare HPOS compatibility in your plugins, switch the store to HPOS with synchronization on, and turn the synchronization off only when all plugins are compatible.
How the switch works
In WooCommerce → Settings → Advanced → Features you choose the order data storage. With “Enable compatibility mode” WooCommerce copies the orders to the new tables in the background (in batches, via Action Scheduler) and then keeps both storages in sync on every change. While sync is on, code that still reads wp_posts keeps working. WooCommerce lists the active plugins that have not declared HPOS compatibility and does not let you switch while incompatible ones are active.
Make your code compatible
A plugin is compatible when it works with orders only through the WC_Order API, never through post functions:
<?php
// BEFORE: works only while orders are posts
$tracking = get_post_meta( $order_id, '_tracking_number', true );
update_post_meta( $order_id, '_tracking_number', $new_value );
// AFTER: works with both storages
$order = wc_get_order( $order_id );
if ( $order ) {
$tracking = $order->get_meta( '_tracking_number', true );
$order->update_meta_data( '_tracking_number', $new_value );
$order->save();
}
Order queries go through wc_get_orders() instead of WP_Query:
<?php
// BEFORE
$query = new WP_Query( array( 'post_type' => 'shop_order', 'post_status' => 'wc-processing', 'posts_per_page' => -1 ) );
// AFTER: returns WC_Order objects from whichever storage is active
$orders = wc_get_orders( array(
'status' => 'processing',
'limit' => -1,
) );
Then declare the compatibility in the main plugin file:
<?php
add_action( 'before_woocommerce_init', function () {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
} );
Reports with SQL
If a report really needs SQL, query the new tables:
<?php
global $wpdb;
$orders = $wpdb->get_results( $wpdb->prepare(
"SELECT o.id, o.status, o.total_amount, o.date_created_gmt, a.first_name, a.last_name, a.email
FROM {$wpdb->prefix}wc_orders o
LEFT JOIN {$wpdb->prefix}wc_order_addresses a ON a.order_id = o.id AND a.address_type = 'billing'
WHERE o.status = %s AND o.date_created_gmt >= %s
ORDER BY o.date_created_gmt DESC
LIMIT 100",
'wc-processing',
gmdate( 'Y-m-d H:i:s', strtotime( '-30 days' ) )
) );
The status in wc_orders keeps the wc- prefix, and the dates are stored in UTC. Code that has to work with both storages can check \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled().
Order of the steps
- Update WooCommerce and all plugins, make a full backup.
- Check the custom code (themes, snippets, your plugins) for
get_post_meta,update_post_meta,shop_orderand SQL onwp_posts, and convert it as above. - Enable compatibility mode and wait until the sync is finished.
- Switch to HPOS with sync still on, and test the checkout, the emails, refunds and the order list.
- After a while without problems, turn the synchronization off: the writes to the post tables stop.
NOTE: Do not turn off the sync while any active plugin is incompatible: such a plugin would read outdated order data from wp_posts and write changes nobody sees. The same CRUD rule applies to checkout fields, see adding a custom checkout field.