Last active
November 23, 2020 15:02
-
-
Save kartikparmar/7304278d21cdefe2c53700efcdf12594 to your computer and use it in GitHub Desktop.
Updating Booking Status - Rich
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function woocommerce_thankyou_change_order_status( $order_id ) { | |
if ( ! $order_id ) return; | |
$order = wc_get_order( $order_id ); | |
if ( $order->get_status() == 'processing' ){ | |
$order->update_status( 'pending' ); | |
// Updating booking status. | |
$order_items = $order->get_items(); | |
foreach ( $order_items as $item_key => $item_value ) { | |
$booking_status = wc_get_order_item_meta( $item_key, '_wapbk_booking_status' ); | |
if ( isset( $booking_status ) && 'paid' === $booking_status ) { | |
$booking_status = 'confirmed'; | |
wc_update_order_item_meta( $item_key, '_wapbk_booking_status', $booking_status ); | |
$booking_id = bkap_common::get_booking_id( $item_key ); | |
if ( $booking_id ) { | |
$new_booking = bkap_checkout::get_bkap_booking( $booking_id ); | |
$new_booking->update_status( $booking_status ); | |
} | |
} | |
} | |
} | |
} | |
add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_change_order_status', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment