woocommerce booking status changes woocommerce order status

房东的猫 提交于 2020-01-03 15:20:50

问题


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

回答1:


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 :)




回答2:


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



回答3:


You need to fetch the status of your order and then check your required condition and update it accordingly.

$order_status = $order->get_status();



回答4:


I know this is an old post, but i have just make it on my latest wordpress/woocommerce install

add_action('woocommerce_booking_cancelled', 'my_booking_cancelled_handler', 10, 1);
function my_booking_cancelled_handler ( $booking_id ) {
  $booking = new WC_Booking( $booking_id );
  $order_id = $booking->get_order_id();
  // check order for your business logic
  // refund or not ;-) it's up to you
}

I hope this helps someone.




回答5:


Hey you can try this hook!!

https://therichpost.com/change-product-order-status-woocommerce-hook

Hope this will help you




回答6:


//Try this


add_action( 'woocommerce_order_status_changed', 'auto_destroy_failed_orders', 10, 4 );

function auto_destroy_failed_orders( $order_id, $old_status, $new_status, $order )
 {
    if ( ( $new_status == 'completed' )) {
        // Order status complete 
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'failed' )) {
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'b2c-shipment' )) {
        // custome status
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'on-hold' )) {
        // Order status to on-hold
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'refunded' )) {
        // Order status to refunded
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'failed' )) {
        // Order status to failed
        $order->update_status( 'custom-status' );

    }else if ( ( $new_status == 'processing' ) ) {
        // Order status to processing
        $order->update_status( 'custom-status' );
    } 
}


来源:https://stackoverflow.com/questions/41553619/woocommerce-booking-status-changes-woocommerce-order-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!