简体   繁体   中英

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.

在此输入图像描述

Here is product info:

  1. Product is virtual product
  2. Stock is disabled

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM