How To Automatically Set WooCommerce PayPal Orders as Completed
In a normal E-commerce operation an order will be made, the customer will pay for it, the order will be fulfilled and the item(s) dispatched, at which point the order will probably be marked as ‘Completed’.
This process is supported in WooCommerce and allows the order to go from ‘Pending’, to ‘Processing’, and finally to ‘Completed’ once the products have been sent out.
This is fine for orders where a physical item exists, but what about virtual orders? There is no notion of postage or sending out items. This is exactly the scenario I had in my latest E-commerce project where the customer had only virtual products on offer.
In this case, when someone paid via PayPal we needed to set the order straight to ‘Completed’ once payment had been received, instead of having to manually log into WordPress and update the order status ourselves.
The steps below explain how I achieved this, as well as how I overcame some problems along the way where I got stuck:
Note: The below assumes that you already have WordPress and WooCommerce in place, and that you have PayPal set up as a payment method.
1. Download the ‘WooCommerce Autocomplete Order’ plugin
First of all, you’ll need to download and activate the ‘WooCommerce Autocomplete Order’ plugin.
Now, at first this plugin sounds like it could be perfect. Unfortunately however the documentation is quite frankly non-existent, especially in the PayPal scenario where a few extra steps are required to get this up and running.
2. Set your products as ‘Virtual’
The above plugin only works for orders containing virtual products so make sure you’ve ticked the ‘Virtual’ box on your products.
3. Activate PayPal IPN
Instant Payment Notification (also know as IPN) is a message service that automatically notifies merchants (in our case WooCommerce) of events related to PayPal transactions. It’s this bit that was missing in my scenario, and the missing piece of the puzzle.
To setup IPN you need to login to PayPal itself, navigate to ‘Profile > My Selling Tools > Instant payment notifications’ and update the information as follows:
Simply enter the URL in the format ‘http://your-domain/?wc-api=WC_Gateway_Paypal‘, enable IPN messages and click ‘Save’.
4. Ensure the ‘Receiver Email’ is correct
The last remaining step is to ensure the ‘Receiver Email’ setting in WooCommerce under the ‘PayPal’ section is set correctly. Normally I believe you should be able to leave this blank, however if you’ve changed it for testing or debugging purposes, it might be worth just making sure that this is correct.
And that’s really it. The final step is to simply carry out an order and hopefully, as soon as the payment has been made via PayPal, the order will automatically be set to ‘Completed’ in the WooCommerce backend. No more having to login and set it manually.