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.

Here is product info:

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_Orderpayment_complete()method.
All payment gateways usepayment_complete()method on a successful payment and Paypal use it onWC_Gateway_Paypal_ResponseClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With