From 1fe8e766a9d0ee5e7c772ad3a8ec389e6bb3a7fe Mon Sep 17 00:00:00 2001 From: Foteini Giannaropoulou Date: Mon, 30 Sep 2024 12:59:58 +0300 Subject: [PATCH] Jetpack Sync: Fix a bug in syncing HPOS 'woocommerce_delete_order' actions (#39562) * Jetpack Sync: Fix a bug in syncing HPOS 'woocommerce_delete_order' actions --- .../fix-sync-woocommerce_delete_order-action | 4 +++ .../modules/class-woocommerce-hpos-orders.php | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 projects/packages/sync/changelog/fix-sync-woocommerce_delete_order-action diff --git a/projects/packages/sync/changelog/fix-sync-woocommerce_delete_order-action b/projects/packages/sync/changelog/fix-sync-woocommerce_delete_order-action new file mode 100644 index 0000000000000..4f357cf354ce0 --- /dev/null +++ b/projects/packages/sync/changelog/fix-sync-woocommerce_delete_order-action @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Jetpack Sync: Fix a bug in syncing HPOS 'woocommerce_delete_order' actions diff --git a/projects/packages/sync/src/modules/class-woocommerce-hpos-orders.php b/projects/packages/sync/src/modules/class-woocommerce-hpos-orders.php index d8b3f943acd36..252808e655d12 100644 --- a/projects/packages/sync/src/modules/class-woocommerce-hpos-orders.php +++ b/projects/packages/sync/src/modules/class-woocommerce-hpos-orders.php @@ -118,9 +118,9 @@ public function init_listeners( $callable ) { add_filter( "jetpack_sync_before_enqueue_woocommerce_after_{$type}_object_save", array( $this, 'expand_order_object' ) ); } add_action( 'woocommerce_delete_order', $callable ); - add_filter( 'jetpack_sync_before_enqueue_woocommerce_delete_order', array( $this, 'expand_order_object' ) ); + add_filter( 'jetpack_sync_before_enqueue_woocommerce_delete_order', array( $this, 'on_before_enqueue_order_trash_delete' ) ); add_action( 'woocommerce_trash_order', $callable ); - add_filter( 'jetpack_sync_before_enqueue_woocommerce_trash_order', array( $this, 'expand_order_object' ) ); + add_filter( 'jetpack_sync_before_enqueue_woocommerce_trash_order', array( $this, 'on_before_enqueue_order_trash_delete' ) ); } /** @@ -259,6 +259,28 @@ public function expand_order_object( $args ) { return $this->filter_order_data( $order_object ); } + /** + * Convert order ID to array. + * + * @access public + * + * @param array $args Order ID. + * + * @return array + */ + public function on_before_enqueue_order_trash_delete( $args ) { + if ( ! is_array( $args ) || ! isset( $args[0] ) ) { + return false; + } + $order_id = $args[0]; + + if ( ! is_int( $order_id ) ) { + return false; + } + + return array( 'id' => $order_id ); + } + /** * Filters only allowed keys from order data. No PII etc information is allowed to be synced. *