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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 10:35:58
Anand Shah

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' );

}

Check out this piece of code

add_action('woocommerce_checkout_order_processed', 'do_something');

function do_something($order_id) { 
   $order = new WC_Order( $order_id ); 
   // Do something
}

For Cash On Delivery method, this worked for me:

add_filter( 'woocommerce_cod_process_payment_order_status', 'prefix_filter_wc_complete_order_status', 10, 3 );

function prefix_filter_wc_complete_order_status( $status, $order ) {
    return 'on-hold';
}

For most other methods, this worked:

add_filter( 'woocommerce_payment_complete_order_status', 'prefix_filter_wc_complete_order_status', 10, 3 );

function prefix_filter_wc_complete_order_status( $status, $order_id, $order ) {
     return 'on-hold';
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!