If you’re using PayPal Standard plugin that comes with WooCommerce, you may have noticed that even if a customer successfully checks out, the status in your WooCommerce orders doesn’t automatically flip over to Processing like completed credit card payments do. This can be frustrating when you have half of your orders automating properly, while the other half require manual status updates.

With this code, you can force a completed PayPal payment to set the order status to PROCESSING, allowing the appropriate actions to trigger in the system automatically (like sending a notification to your customer that their order was received).

Requirements:

  • PHP
  • Access to your functions.php file

Note: This works with WooCommerce 2.0+ and the sample code above will no longer work with WC 1.6.6 and previous versions.

Original Article

Before

After

PHP

Add this code to your child theme’s functions.php file (very end).

[cc lang=”php”]

// AUTO COMPLETE ORDERS PAYPAL
function virtual_order_payment_complete_order_status( $order_status, $order_id ) {

$order = wc_get_order( $order_id );

if ( ‘processing’ == $order_status &&
( ‘on-hold’ == $order->status || ‘pending’ == $order->status || ‘failed’ == $order->status ) ) {

$virtual_order = null;

if ( count( $order->get_items() ) > 0 ) {

foreach( $order->get_items() as $item ) {

if ( ‘line_item’ == $item[‘type’] ) {

$_product = $order->get_product_from_item( $item );

if ( ! $_product->is_virtual() ) {
// once we’ve found one non-virtual product we know we’re done, break out of the loop
$virtual_order = false;
break;
} else {
$virtual_order = true;
}
}
}
}

// virtual order, mark as completed
if ( $virtual_order ) {
return ‘completed’;
}
}

// non-virtual order, return original status
return $order_status;
}
add_filter( ‘woocommerce_payment_complete_order_status’, ‘virtual_order_payment_complete_order_status’, 10, 2 );

[/cc]

Share This