Multisite Order Sync: Hook Reference

rudr_mos_is_auto_mode

By default, whether the orders should be synced manually or not can be managed by a specific settings checkbox that can be found in each site’s settings:

Auto-sync orders in WooCommerce Multisite

However, it can also be overridden with the rudr_mos_is_auto_mode filter hook.

$is_auto_mode = apply_filters( 'rudr_mos_is_auto_mode', $is_auto_mode, $order, $blog_id );
$is_auto_modebool
Whether the auto-syncing for orders is allowed (true) or not (false).
$orderWC_Order
An order object.
$blog_idint
Current store (blog) ID, from which the current order is about to get synced.

Example. Never auto-sync orders with a specific meta field

For example, let’s assume that you have a custom third-party plugin, which adds a custom WooCommerce admin page where the orders are displayed. However, when this plugin displays a list of orders, it also automatically assigns a custom field to each order and re-saves it. Definitely, we don’t want orders to be re-synced that way to the master store.

So, we can prevent it from doing that using the code snippet below:

add_filter( 'rudr_mos_is_auto_mode', function( $is_auto_mode, $order ) {
	
	// the custom field that prevents orders to be auto-synced
	$meta_value = $order->get_meta( '_my_custom_field' );
	
	if( $meta_value ) { // any value
		$is_auto_mode = false;
	}
	
	// you can also check it for a specific value
	// if( 'value123' === $meta_value ) {
	//   $is_auto_mode = false;
	// }

	return $is_auto_mode;

}, 25, 2 );

rudr_mos_allow_rest_api_sync

This hook allows you to prevent orders from being synced when these orders are created on the website with the WooCommerce REST API.

 $is_rest_api_sync = apply_filters( 'rudr_mos_allow_rest_api_sync', $is_rest_api_sync );
$is_rest_api_syncbool
Whether syncing of orders created with the REST API is allowed (defaults to true).

rudr_mos_order_number

This filter hook allows you to override order numbers of synced orders displayed on the master store in any possible way.

$order_number = apply_filters( 'rudr_mos_order_number', $order_number, $order, $source_store_id, $source_order_id );
$order_numberstring
Order number.
$orderWC_Order
An order object.
$source_store_idint
Source store (blog) ID, from which the current order was synced.
$source_order_idint
The original order ID on the source store.

Example. Use both the source store ID and the source order ID in the order number

add_filter( 'rudr_mos_order_number', function( $order_number, $order, $source_store_id, $source_order_id ) {
	
	return $source_order_id . '-' . $source_store_id;
	
}, 99, 4 );

Using the code snippet on the master store will result in the orders being displayed the following way:

Custom order numbers on the master store
101 and 17 are the order IDs in their original stores, where these orders were placed; 5 and 2 are store IDs.