From 26043fa0ea119716f1850f6c16e27458db6e1d00 Mon Sep 17 00:00:00 2001 From: Jorge Torres Date: Fri, 11 Aug 2023 14:57:08 -0300 Subject: [PATCH] Transitioning HPOS orders from auto-draft should trigger new order hook --- .../Internal/DataStores/Orders/OrdersTableDataStore.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index ee4563298a3..61932d0f815 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -2339,6 +2339,9 @@ FROM $order_meta_table * @param \WC_Order $order Order object. */ public function update( &$order ) { + $previous_status = ArrayUtil::get_value_or_default( $order->get_data(), 'status' ); + $changes = $order->get_changes(); + // Before updating, ensure date paid is set if missing. if ( ! $order->get_date_paid( 'edit' ) @@ -2372,6 +2375,12 @@ FROM $order_meta_table $order->apply_changes(); $this->clear_caches( $order ); + // For backwards compatibility, moving an auto-draft order to a valid status triggers the 'woocommerce_new_order' hook. + if ( ! empty( $changes['status'] ) && 'auto-draft' === $previous_status ) { + do_action( 'woocommerce_new_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment + return; + } + do_action( 'woocommerce_update_order', $order->get_id(), $order ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment }