Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

woocommerce booking status changes woocommerce order status

I'm using woocommerce bookings. I'm trying to trigger woocommerce order status to refund if the woocommerce_booking status is cancelled. I tried this code but it's not working.

global $woocommerce;
$order = new WC_Order( $order_id );
if ( 'cancelled' == $order->status ) {
   $order->update_status('refund', 'order_note');
}
like image 284
PPrevoo Avatar asked Jan 09 '17 17:01

PPrevoo


2 Answers

To update order status on cancel status

add_action('woocommerce_cancelled_order','change_status_to_refund', 10, 1);
 function change_status_to_refund($order_id) {
    $order = new WC_Order( $order_id );
    $order->update_status('refund', 'order_note');
    exit;
 }

I hope it will help you. Thanks :)

like image 159
dineshkashera Avatar answered Oct 02 '22 22:10

dineshkashera


add_action( 'woocommerce_order_status_changed', 'wc_order_status_changed', 99, 3 );

function wc_order_status_changed( $order_id, $old_status, $new_status ){
    if( $new_status == "cancelled" ||  $new_status == "refunded" ) {
        //code here.
    }
}

If you want use in some class action must be like this:

add_action( 'woocommerce_order_status_changed', array($this, 'wc_order_status_changed'), 99, 3 );
like image 30
Rostiel Avatar answered Oct 02 '22 22:10

Rostiel