Add filter woocommerce_hpos_enable_sync_on_read to disable sync on read with HPOS sync enabled.

This commit is contained in:
Vedanshu Jain 2023-09-05 14:33:00 +05:30
parent bbe053e16e
commit 1d0665a8dd
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Add filter woocommerce_hpos_enable_sync_on_read to disable sync on read with HPOS sync enabled.

View File

@ -1111,6 +1111,18 @@ WHERE
}
$data_sync_enabled = $data_synchronizer->data_sync_is_enabled();
if ( $data_sync_enabled ) {
/**
* Allow opportunity to disable sync on read, while keeping sync on write disabled. This adds another step as a large shop progresses from full sync to no sync with HPOS authoritative.
* This filter is only executed if data sync is enabled from settings in the first place as it's meant to be a step between full sync -> no sync, rather than be a control for enabling just the read on sync. Sync on read without sync on write is problematic as any update will reset on the next read, but sync on write without sync on read is fine.
*
* @param bool $read_on_sync_enabled Whether to sync on read.
*
* @since 8.1.0
*/
$data_sync_enabled = apply_filters( 'woocommerce_hpos_enable_sync_on_read', $data_sync_enabled );
}
$load_posts_for = array_diff( $order_ids, array_merge( self::$reading_order_ids, self::$backfilling_order_ids ) );
$post_orders = $data_sync_enabled ? $this->get_post_orders_for_ids( array_intersect_key( $orders, array_flip( $load_posts_for ) ) ) : array();