Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order status processing issue on successful payment from Paypal in Woocommerce

I am having strange issue and this happens sometimes, when user pay for a course via paypal the order status changed from pending to processing instead of completed.

In this image IPIN notification received but still order is in processing stage, what could causing this issue. I tried to replicate this issue but it does not replicated at my end, It happens sometimes.

enter image description here

Here is product info:

  1. Product is virtual product
  2. Stock is disabled

enter image description here

like image 775
Hemant Kumar Avatar asked Nov 25 '25 08:11

Hemant Kumar


1 Answers

If you are selling only virtual products, you can force order status to "completed" for Paypal on payment complete function, this way:

add_filter('woocommerce_payment_complete_order_status', 'paypal_payment_complete_order_status', 10, 2 );
function paypal_payment_complete_order_status( $status, $order_id, $order ){
    if( $order->get_payment_method() === 'paypal' )
        $status = 'completed';

    return $status;
}

Code goes in function.php file of your active child theme (or active theme). Tested and work.

This hook is only triggered on successful payment and has originally 2 possible order status values "processing" or "completed" (depending if "processing" is required). So this answer code just force the order status to "completed" targeting Paypal payment gateway (for virtual products). This hook is located on WC_Order payment_complete() method.
All payment gateways use payment_complete() method on a successful payment and Paypal use it on WC_Gateway_Paypal_Response Class.

like image 109
LoicTheAztec Avatar answered Nov 27 '25 21:11

LoicTheAztec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!