From 1d0665a8dded7267142dd6275095701d929661af Mon Sep 17 00:00:00 2001 From: Vedanshu Jain Date: Tue, 5 Sep 2023 14:33:00 +0530 Subject: [PATCH] Add filter woocommerce_hpos_enable_sync_on_read to disable sync on read with HPOS sync enabled. --- .../woocommerce/changelog/add-filter-sync-on-read | 4 ++++ .../DataStores/Orders/OrdersTableDataStore.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 plugins/woocommerce/changelog/add-filter-sync-on-read diff --git a/plugins/woocommerce/changelog/add-filter-sync-on-read b/plugins/woocommerce/changelog/add-filter-sync-on-read new file mode 100644 index 00000000000..f1bdd04a448 --- /dev/null +++ b/plugins/woocommerce/changelog/add-filter-sync-on-read @@ -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. diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index 487f401daa5..1f04ed5b67a 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -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();