How To Change Order Status From Processing To Completed WooCommerce For Online Payments

By default WooCommerce marks each successful checkout order as Processing. The main reasons why the order is marked as Processing rather than Completed is

  • The product might have be paid via Cash on Delivery method. In such a case, it is required the payment to be verified during delivery to mark is Completed.
  • The payment for the order might be via other offline methods which require verification in order to be marked as Completed.

However , if you are dealing with digital products / courses etc in most cases you would like the order to be marked automatically as Completed if payment is received.

In such a case, by adding a simple Code Snippet code into functions.php file of your theme / Child theme , you can automatically mark these processed orders as completed.

Code Snippet to Automatically Mark WooCommerce Processing Order to Completed

add_action('woocommerce_order_status_changed', 'xen_auto_complete_by_payment_method');

function xen_auto_complete_by_payment_method($order_id)
{

if ( ! $order_id ) 
{
return;
}

global $product;
$order = wc_get_order( $order_id );

if ($order->data['status'] == 'processing') 
{
$payment_method=$order->get_payment_method();
if ($payment_method!="cod")
{
$order->update_status( 'completed' );
}
}

}

If you closely observe the code if ($payment_method!=”cod”) specifies, if the payment method selected is not COD ( Cash on Delivery) – please update the order status to Completed. If not keep it as Processing.

So next time, in case you wish to autocomplete your digital products orders on succesful payment , you can use the above snippet.

Similar Posts