Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update woocommerce order status after payment process complete and redirect to store

I am using woo-commerce for my shopping site. I want to update the order status to complete after payment was made and then return to a success page.

I used the following code:

add_filter( 'woocommerce_payment_complete_order_status', 'my_change_status_function', 10, 2 );

function my_change_status_function ($order_status, $order_id) {
  $order = new WC_Order($order_id);
  return 'completed';
}

But this function is called before the payment was made and redirects to the payment page.

I want to change the status after the payment was completed and then return to redirect URL.

Here is my redirect link:

http://example.com/checkout/order-received/82/?key=wc_order_5614e28c9d183&state=return

But the status is not changing when I use the woocommerce_payment_complete_order_status hook. The hook should be called after the payment is completed.

like image 878
himanshu archirayan Avatar asked Oct 07 '15 09:10

himanshu archirayan


Video Answer


1 Answers

Try using the following code in your plugin

add_action( 'woocommerce_payment_complete', 'my_change_status_function' );

function my_change_status_function( $order_id ) {

    $order = wc_get_order( $order_id );
    $order->update_status( 'completed' );

}
like image 66
Anand Shah Avatar answered Sep 23 '22 13:09

Anand Shah