Overview
Who is This Guide For?
This guide assumes the following:
- You are already using the PayPal for WooCommerce plugin to take payments with Express Checkout and/or Payments Pro.
- You would like to automatically update the WooCommerce order status when payments are completed.
Introduction
The PayPal Standard integration included with WooCommerce uses PayPal IPN to update the order status when payments are completed. We initially planned to do the same thing with PayPal for WooCommerce, however, we did not like the idea of limiting the power of PayPal IPN. We decided to build a separate, stand-alone plugin: PayPal IPN for WordPress.
In this guide we will cover the steps involved in building the PayPal IPN for WordPress plugin into your theme in order to automatically update the WooCommerce order status when a PayPal Express Checkout or Payments Pro transaction is completed.
Advantages of Updating with PayPal IPN
- Correct handling of pending payments (e-checks, payment holds, etc.) so your order status is not updated until a payment actually clears and is fully complete.
- Updates happen automatically in real-time. No more manual updates!
Get Our IPN Plugin
Get the plugin version of this solution for quick and easy installation!
Step 1 – Install and Configure PayPal IPN for WordPress
In order to setup automatic updates from your PayPal account to your WordPress / WooCommerce website you will need to install our PayPal IPN for WordPress plugin and configure it with your PayPal account.
Step 2 – Set the PayPal IPN Hook in functions.php
Open the functions.php file in your theme (child) and add the following code.
add_action('paypal_ipn_for_wordpress_payment_status_completed', 'angelleye_update_wc_order_status', 10, 1); function angelleye_get_paypal_order($raw_custom) { if (( $custom = json_decode($raw_custom) ) && is_object($custom)) { $order_id = $custom->order_id; $order_key = $custom->order_key; } elseif (preg_match('/^a:2:{/', $raw_custom) && !preg_match('/[CO]:\+?[0-9]+:"/', $raw_custom) && ( $custom = maybe_unserialize($raw_custom) )) { $order_id = $custom[0]; $order_key = $custom[1]; } else { return false; } if (!$order = wc_get_order($order_id)) { $order_id = wc_get_order_id_by_order_key($order_key); $order = wc_get_order($order_id); } $order_key_value = version_compare(WC_VERSION, '3.0', '<') ? $order->order_key : $order->get_order_key(); if (!$order || $order_key_value !== $order_key) { return false; } return $order; } function angelleye_update_wc_order_status($posted) { if (!empty($posted['custom']) && ( $order = angelleye_get_paypal_order($posted['custom']) )) { $order_id = version_compare(WC_VERSION, '3.0', '<') ? $order->id : $order->get_id(); if (!empty($order_id)) { $order = new WC_Order($order_id); $order->update_status('completed'); } } }
Step 3 – Upload functions.php
All that’s left to do is upload your functions.php file to your web server.
From now on, any orders that come through PayPal and have a matching WooCommerce Order will automatically update the order status to Completed!
Looking for Live Help?
Schedule a live meeting with Drew Angell, PayPal Certified Developer, and get all of your questions or concerns answered.
Featured PayPal Products and Services
-
PayPal Support
$100.00 -
PayPal for WooCommerce
FREE! -
WooCommerce Multiple PayPal Accounts Plugin
FREE! -
PayPal Shipment Tracking for WooCommerce
$49.99 -
Offers for WooCommerce
$59.99 -
WordPress PayPal Invoice Plugin
$20.00 -
PayPal Webhooks for WordPress
$79.99 -
Sale!
PayPal IPN for WordPress
Original price was: $59.99.$49.99Current price is: $49.99.
Hi Andrew,
Will this work with the integrated Paypal Standard add-on in Woocommerce ? I cannot make the IPN working properly with the built in features of Woocommerce. All orders stays in pending status.
Regards.
Technically, this process should work for that, yes. If that’s not working for you, though, you must have a problem going on that could also affect our IPN plugin. You can certainly give it a shot, though, and see if it works out for you. Either way, I would also recommend you go ahead and use our plugin with Express Checkout, too. There are quite a few benefits of Express Checkout.
Hope that helps!
are you using Bluehost by chance? We are suffering from the same issue of some paid PayPal orders being stuck as Pending and never become set to Processing. We use Bluehost and one article suggest that Bluehost uses a mod_security in .htaccess that blocks some IPN notifications.
Hi Andrew,
i used the code and it works…but i need the update status: payment complete ready/awaiting shipment. What is the correct one? Hope you can help. Many thanks in advance!
Best regards,
Alexander
If it’s awaiting shipment then you would want to leave it in the Processing status, which is the default. Completed assumes everything is completely done, including shipment.
Hello. I have an Woocommerce website. I want to update/sync tracking code from my website to each transaction in PayPal.
So, how can I make it?
THank you
I need you to clarify that a little bit for me. Are you referring to shipment tracking? So you want to push tracking numbers back into the PayPal system? Unfortunately, this is not something that is available via PayPal’s API. I’ve been begging for it for years, and it’s just not something they’ve gotten done. 🙁
They just added tracking to the API !!!
https://developer.paypal.com/docs/api/tracking/v1/
Yes, I saw this! I’ll be adding a video to our YouTube channel about it soon. 🙂
Hi Andrew,
Is there a specific section where I need to put the hook in functions.php or can I just paste it after all other functions? I’m not a developer and I don’t know exactly where I need to paste it in the function.php file.
Many thanks
You can put it after all the other functions and that will be fine. 🙂
Hello Andrew,
Excelent post, clear, on the spot and updated! Congratulation on your work.
Got a request if possible. Can we add a check so that only orders marked as Processing to auto-upadated to Complete? At our shop there are many canceled and pending payment orders that they need to retain their status but a paid one doesnt need anything else (shipping for example) to be complete and the client to receive the Order completed email.
Thank you for your great work,
Nikos
Hi Nikos,
I’m sorry for the delay getting back to you. I’m glad you found this helpful! Yes, you could certainly adjust the code to check the current status prior to the update. You would just need to pull the current status out of the order object that is setup in the sample and then build an if/then statement based on that. If you need more direct help with this (we can build a new function with these adjustments for you) then you can submit an order for premium support and we’ll do that. We are about a week out on these requests, though, just so you know.
Hi, I am having issues with the order status even though paypal processed it correctly.
Unpaid order cancelled – time limit reached. Order status changed from Pending payment to Cancelled.
order_note Order status changed from Cancelled to Pending payment.
Can you help?
Are you using our PayPal for WooCommerce plugin to process your order payments or something else?
this will only work if the payment was process through paypal right?
what if i have other payment gateways?
Yes, this procedure is specific to orders paid via PayPal. If you’re using some other gateway then you would have to see if they provide a similar service to PayPal IPN, and if so, then you could this up in a similar fashion. Of course, you wouldn’t have the foundation plugin to start with, so you’d have to build the entire thing out.
Can you tell me-
If an order comes in, and payment has been completed at Paypal- it will show in my Woocommerce as “processing”
I assume this is because the order has not been shipped yet through paypal.
If I then go to Paypal and ship the order- (now marked as “shipped” in paypal)
I would like it to auto-update the order in woocommerce to now show as “complete”
Is it supposed to work that way?
Because on my install, if I ship thru paypal, it always stays as “processing” in my woocommerce and I have to manually set it to “complete”.
however, if i refund an order, it will auto-update my woocommerce to show the order as “refunded”
so it seems it is getting at least the refund notification from paypal- but I would really like it to switch to “complete” in woocommerce once I have shipped the order thru paypal.
Anything I’m doing wrong?
Hi Brian,
PayPal’s IPN tool can be used to resolve this for you. We have an article specific to this I would recommend you check out. Please take a look at that and let me know if you have any specific questions or concerns. Thanks!
I am using default Woocommerce order status but due to some customers feedback I am looking to change the order status in 3 different stage for instance: time of booking, payment process is complete and product delivery by default there are 4 to 5 statues. Is there any way I can reduce those extra status? I have seen people recommending custom Woocommerce order status for that but not sure about it. Here is a resource for reference:
https://www.cloudways.com/blog/create-woocommerce-custom-order-status
That’s really a personal / business preference how you want to handle that. This article gives you details for how to update the Woo order status based on an IPN, but what exactly you want that status to be at that point is up to your and however you have your workflow built into Woo.
Hey Andrew,
Great plugin so far. Is there a way to prevent the “New Customer Order” email from WooCommerce from sending until PayPal marks the payment from Pending to Complete?
It would be a big help to us if the “New Customer Order” email came in after PayPal has verified and marked the payment as complete.
The default procedure for WooCommerce is to set to Processing (not Pending) and that is when it triggers the New Order email. If you want to adjust that so the New Order email gets sent on Completed instead then you would need to customize that at the WooCommerce level. That would be outside the scope of our plugin, but you can submit a quote request for us to help you more directly with that if you’d like.
Hi there,
Unfortunately this is not working.. We have placed the paid plugin, correct IPN and the code on functions.php but the orders are still getting to Processing and not Completed.
Did you make sure to adjust for your invoice ID prefix set, if any? If that doesn’t help, please submit a ticket to our help desk and we’ll get you taken care of.
You need to change “update_wc_order_status” from example add_action(‘paypal_ipn_for_wordpress_payment_status_completed’, ‘update_wc_order_status’, 10, 1) to “angelleye_update_wc_order_status”. And it will be add_action(‘paypal_ipn_for_wordpress_payment_status_completed’, ‘angelleye_update_wc_order_status’, 10, 1);
Hello, I am looking for a way to change the default order status on Paypal for woocommerce when the charge mode is “authorize” and not “capture”. Is there a way to do that?
Yes, when you choose Authorization as the action type it will display an additional option to set the order status accordingly. .