From 0e6b3965d1237b2f57f4a3ddb0b6b92c3c1296eb Mon Sep 17 00:00:00 2001 From: sumaisa-mou Date: Wed, 25 Feb 2026 11:53:08 +0600 Subject: [PATCH 1/2] Fix wooCommerce order status --- .../Core/Ecommerce/Platforms/WooCommerce.php | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/includes/Core/Ecommerce/Platforms/WooCommerce.php b/includes/Core/Ecommerce/Platforms/WooCommerce.php index 10fd4f1..a67df54 100644 --- a/includes/Core/Ecommerce/Platforms/WooCommerce.php +++ b/includes/Core/Ecommerce/Platforms/WooCommerce.php @@ -99,10 +99,10 @@ public function orders( array $args = array() ) { */ public function register_hooks() { // New order created hook - add_action( 'woocommerce_new_order', array( $this, 'handle_order' ), 10, 2 ); + add_action( 'woocommerce_new_order', array( $this, 'handle_new_order' ), 10, 2 ); // Order status changed hook (handles pending payment, completed, etc.) - add_action( 'woocommerce_order_status_changed', array( $this, 'handle_order' ), 10, 4 ); + add_action( 'woocommerce_order_status_changed', array( $this, 'handle_order_status_changed' ), 10, 4 ); // Pending payment status specific hook add_action( 'woocommerce_order_status_pending', array( $this, 'handle_pending_payment' ), 10, 1 ); @@ -121,45 +121,42 @@ public function register_hooks() { } /** - * Handling pending payment status + * Handle new order created * * @param int $order_id Order ID + * @param \WC_Order $order Order object + */ + public function handle_new_order( $order_id, $order ) { + $this->process_order( $order_id, $order ); + } + + /** + * Handle order status changed * - * @return void + * @param int $order_id Order ID + * @param string $status_from From status + * @param string $status_to To status + * @param \WC_Order $order Order object */ - public function handle_pending_payment( $order_id ) { - $order = wc_get_order( $order_id ); + public function handle_order_status_changed( $order_id, $status_from, $status_to, $order ) { + $this->process_order( $order_id, $order ); + } + /** + * Process order - shared logic for new order and status change + * + * @param int $order_id Order ID + * @param \WC_Order $order Order object + */ + private function process_order( $order_id, $order ) { if ( ! $order ) { - return; - } - - if ( ! $this->is_valid_order_item( $order->get_type() ) ) { - return; + $order = wc_get_order( $order_id ); } - if ( ! Settings::instance()->is_enabled() ) { + if ( ! $order ) { return; } - $payload = OrderResource::single( $order ); - - wemail()->api - ->send_json() - ->ecommerce() - ->orders( $order_id ) - ->put( $payload ); - } - - /** - * Handling order - * - * @param $order_id - * @param $status_from - * @param $status_to - * @param $order \WC_Order - */ - public function handle_order( $order_id, $order ) { if ( ! $this->is_valid_order_item( $order->get_type() ) ) { return; } From 90a59ea86d9563a7838afe70ed02a34134408d19 Mon Sep 17 00:00:00 2001 From: sumaisa-mou Date: Wed, 25 Feb 2026 11:56:09 +0600 Subject: [PATCH 2/2] Refactor --- .../Core/Ecommerce/Platforms/WooCommerce.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/includes/Core/Ecommerce/Platforms/WooCommerce.php b/includes/Core/Ecommerce/Platforms/WooCommerce.php index a67df54..2ba8822 100644 --- a/includes/Core/Ecommerce/Platforms/WooCommerce.php +++ b/includes/Core/Ecommerce/Platforms/WooCommerce.php @@ -120,6 +120,35 @@ public function register_hooks() { add_action( 'delete_product_cat', array( $this, 'handle_category_delete' ), 10, 3 ); } + /** + * Handle pending payment status + * + * @param int $order_id Order ID + */ + public function handle_pending_payment( $order_id ) { + $order = wc_get_order( $order_id ); + + if ( ! $order ) { + return; + } + + if ( ! $this->is_valid_order_item( $order->get_type() ) ) { + return; + } + + if ( ! Settings::instance()->is_enabled() ) { + return; + } + + $payload = OrderResource::single( $order ); + + wemail()->api + ->send_json() + ->ecommerce() + ->orders( $order_id ) + ->put( $payload ); + } + /** * Handle new order created *