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!
Download the Plugin Version
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!
Need Additional 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 Help
$100.00 -
PayPal for WooCommerce
FREE! -
WooCommerce Multiple PayPal Accounts Plugin
$99.99 -
PayPal Shipment Tracking for WooCommerce
$49.99 -
Sale!
PayPal for WooCommerce – Credit Card Split Payment
$99.99$49.99 -
Offers for WooCommerce
$59.99 -
WordPress PayPal Invoice Plugin
FREE! -
WordPress Maintenance
$75.00 on the 1st of each month
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);