diff --git a/includes/api/order.php b/includes/api/order.php index 3b3e0cf9..08dd41db 100644 --- a/includes/api/order.php +++ b/includes/api/order.php @@ -65,9 +65,15 @@ function createWcOrder(WP_REST_Request $request) $orderIdFromHash = null; if (isHposEnabled()) { - $updateOrderStatus = 'checkout-draft'; - }else{ - $updateOrderStatus = 'draft'; + $updateOrderStatus = 'checkout-draft'; + } else { + // Check if WooCommerce supports the "checkout-draft" status (added in newer versions). + $postStatus = get_post_status_object('wc-checkout-draft'); + if ($postStatus) { + $updateOrderStatus = 'checkout-draft'; + } else { + $updateOrderStatus = 'draft'; // Older WooCommerce versions fallback + } } if ($orderIdFromHash == null) { @@ -300,10 +306,18 @@ function updateOrderStatus($orderId, $orderStatus) $order->update_status($orderStatus); $order->save(); }else{ - wp_update_post(array( - 'ID' => $orderId, - 'post_status' => $orderStatus, - )); + // Handling order status update for WooCommerce versions that do not support HPOS. + // We are unsure if older versions use `wp_update_post()`, while newer versions may use `$order->update_status()`. + // To maintain compatibility across different WooCommerce versions, we add an additional if-else condition. + if (!isHposEnabled()) { // Explicitly checking if HPOS is NOT enabled + $order->update_status($orderStatus); + $order->save(); // Save changes + } else { + wp_update_post([ + 'ID' => $orderId, + 'post_status' => $orderStatus, + ]); + } } } diff --git a/includes/api/save-abandonment-data.php b/includes/api/save-abandonment-data.php index 3450a4d0..039cdc73 100644 --- a/includes/api/save-abandonment-data.php +++ b/includes/api/save-abandonment-data.php @@ -54,10 +54,10 @@ function saveCartAbandonmentData(WP_REST_Request $request) $orderStatus = $order->get_status(); - if ($orderStatus === 'draft' && isset($razorpayData['customer_details']['shipping_address'])) { + + if (($orderStatus === 'draft' || $orderStatus ==='checkout-draft') && isset($razorpayData['customer_details']['shipping_address'])) { //Update the order status to wc-pending as we have the customer address info at this point. updateOrderStatus($wcOrderId, 'wc-pending'); - } } diff --git a/includes/razorpay-webhook.php b/includes/razorpay-webhook.php index 2c6e271c..81e6f147 100644 --- a/includes/razorpay-webhook.php +++ b/includes/razorpay-webhook.php @@ -323,7 +323,7 @@ public function paymentAuthorized(array $data) return; } - if ($orderStatus == 'draft') { + if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') { updateOrderStatus($orderId, 'wc-pending'); } @@ -429,7 +429,7 @@ protected function paymentPending(array $data) return; } - if ($orderStatus == 'draft') { + if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') { updateOrderStatus($orderId, 'wc-pending'); }