Change Woocommerce order status based on payment gateway and transition status Change Woocommerce order status based on payment gateway and transition status wordpress wordpress

Change Woocommerce order status based on payment gateway and transition status


Here is an example using woocommerce_order_status_changed hook where you can target your orders statuses transition "from" and "to", to change the order status to any other.

In this example I target the statuses "from" delivery-unpaid and "to" delivery-paid to change the order status to completed.

As you can see in Woocommerce the Order statuses are slugs (all in lowercase)

You can target, at the same time, a specific payment gateway ID like Stripe using something like:

add_action( 'woocommerce_order_status_changed', 'change_order_status_conditionally', 10, 4 );function change_order_status_conditionally( $order_id, $status_from, $status_to, $order ) {    if( $order->get_payment_method() === 'stripe' && $status_from === 'delivery-unpaid' && $status_to === 'delivery-paid' ) {        $order->update_status( 'completed' );    }}

Code goes in function.php file of your active child theme (or active theme). It should works.

As you can see you can add as many IF statements targeting the order statuses transitions that you need to change it to any other status and payment gateways.

Code goes in function.php file of your active child theme (or active theme). It should works.