Skip to content

PLUGIN1CC-4234 Fix HPOS disabled causing order status to remain pending #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions includes/api/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
]);
}
}

}
Expand Down
4 changes: 1 addition & 3 deletions includes/api/save-abandonment-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

}
}

Expand Down
4 changes: 2 additions & 2 deletions includes/razorpay-webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected function paymentAuthorized(array $data)
return;
}

if ($orderStatus == 'draft') {
if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') {
updateOrderStatus($orderId, 'wc-pending');
}

Expand Down Expand Up @@ -400,7 +400,7 @@ protected function paymentPending(array $data)
return;
}

if ($orderStatus == 'draft') {
if ($orderStatus == 'checkout-draft' || $orderStatus == 'draft') {
updateOrderStatus($orderId, 'wc-pending');
}

Expand Down
Loading