diff --git a/includes/api/order.php b/includes/api/order.php index 15ebb312..14b0737d 100644 --- a/includes/api/order.php +++ b/includes/api/order.php @@ -62,7 +62,13 @@ function createWcOrder(WP_REST_Request $request) if (isHposEnabled()) { $updateOrderStatus = 'checkout-draft'; }else{ - $updateOrderStatus = 'draft'; + // Handle compatibility for WooCommerce versions where "checkout-draft" may not be used. + // Older versions might use "draft" instead of "checkout-draft". + if (!isHposEnabled()) { + $updateOrderStatus = 'checkout-draft'; // Fallback for WooCommerce versions that do not support "draft" + } else { + $updateOrderStatus = 'draft'; // Default for non-HPOS cases where "draft" is supported + } } if ($orderIdFromHash == null) { @@ -265,10 +271,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 877e060b..0f37e821 100644 --- a/includes/api/save-abandonment-data.php +++ b/includes/api/save-abandonment-data.php @@ -44,10 +44,8 @@ function saveCartAbandonmentData(WP_REST_Request $request) $orderStatus = $order->get_status(); - if ($orderStatus === 'draft' && isset($razorpayData['customer_details']['shipping_address'])) { - //Update the order status to wc-pending as we have the customer address info at this point. + 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 68a169d2..04940e04 100644 --- a/includes/razorpay-webhook.php +++ b/includes/razorpay-webhook.php @@ -305,7 +305,7 @@ protected function paymentAuthorized(array $data) return; } - if ($orderStatus == 'draft') { + if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') { updateOrderStatus($orderId, 'wc-pending'); } @@ -400,7 +400,7 @@ protected function paymentPending(array $data) return; } - if ($orderStatus == 'draft') { + if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') { updateOrderStatus($orderId, 'wc-pending'); }