How to Use the Same Order Numbers for Synced Orders
When you sync WooCommerce orders from the original store to a target store, you may notice that order numbers of the same order on the target and original stores are different.
Is there a way to change that?
Long story short, WooCommerce uses order numbers in the database as auto-incremented, unique order IDs. We simply can not change that.
However, there is a way – we can use the woocommerce_order_number WooCommerce hook on the target store, which allows us to change what is displayed as an order ID in the WooCommerce admin dashboard, emails, etc. More info in the separate tutorial.
So, if you want an original ID of a synced order to be displayed on the target store, just use the code snippet below:
add_filter( 'woocommerce_order_number', 'rudr_original_order_number', 25, 2 );
function rudr_original_order_number( $order_number, $order ) {
// get the information about synced order
$synced_data = $order->get_meta( '_wos_order_sync_data' );
if( ! $synced_data ) {
return $order_number;
}
// provide an URL of an initial (sending) store without "https://"
$url = 'store2.rudrastyh.com';
if( ! empty( $synced_data[ $url ] ) ) {
$order_number = $synced_data[ $url ];
}
return $order_number;
}This snippet must be added to the target stores only.
If you don’t know how to use it, please check this guide. And don’t forget to replace the example URL on line 10.