Woocommerce booking status status changes woocommerce order status

I use woocommerce booking. I am trying to return the woocommerce order status if the woocommerce_booking status woocommerce_booking canceled. I tried this code but it does not work.

 global $woocommerce; $order = new WC_Order( $order_id ); if ( 'cancelled' == $order->status ) { $order->update_status('refund', 'order_note'); } 
+5
source share
8 answers

To update order status with cancellation 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; } 

Hope this helps you. Thanks:)

+6
source
 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 to use in some class actions, it should be like this:

 add_action( 'woocommerce_order_status_changed', array($this, 'wc_order_status_changed'), 99, 3 ); 
+1
source

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

 $order_status = $order->get_status(); 
0
source

I know this is an old post, but I just did it on my latest version of 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 up to you } 

I hope this helps someone.

0
source

Hey, you can try this hook!

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

Hope this helps you

0
source

Your code is good, but I would like to know on which hook / event you are performing this action.

For example, on the page for receiving an order on the admin page, where you will receive $ order_id for the implementation of your action with the code.

0
source
 add_action('woocommerce_order_status_pool-payment-rec', 'auto_change_booking_status_to_paid', 20, 2 ); function auto_change_booking_status_to_paid( $order_id, $order ) { if( $order->get_status() === 'pool-payment-rec' ) { foreach( $order->get_items() as $item_id => $item ) { $product = wc_get_product($item['product_id']); if( $product->get_type() === 'booking' ) { $booking_ids = WC_Booking_Data_Store::get_booking_ids_from_order_item_id( $item_id ); foreach( $booking_ids as $booking_id ) { $booking = new WC_Booking($booking_id); if( $booking->get_status() != 'paid' ) $booking->update_status( 'paid', 'order_note' ); } } } } } 

you have to try this.

0
source

// Set custom order status @ WooCommerce checkout process

 add_action( 'woocommerce_thankyou', 'bbloomer_thankyou_change_order_status' ); function bbloomer_thankyou_change_order_status( $order_id ){ if( ! $order_id ) return; $order = wc_get_order( $order_id ); // Status without the "wc-" prefix $order->update_status( 'custom-status' ); } 
0
source

Source: https://habr.com/ru/post/1262537/


All Articles