Last active
December 4, 2022 09:52
-
-
Save kartikparmar/f4ced72bab4b04f3d691585a61a4a225 to your computer and use it in GitHub Desktop.
When manually creating booking, set order status to pending payment and booking status to pending-confirmation
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 bkap_booking_status_on_create_order( $status ) { | |
if ( is_admin() ) { | |
if ( isset( $_POST['original_post_status'] ) ) { | |
return $status; | |
} | |
$status = 'pending-confirmation'; | |
} | |
return $status; | |
} | |
add_filter( 'bkap_booking_status_on_create_order', 'bkap_booking_status_on_create_order', 10, 1 ); | |
function bkap_manual_gcal_booking_order_status( $status ) { | |
if ( is_admin() ) { | |
$status = 'pending'; | |
} | |
return $status; | |
} | |
add_filter( 'bkap_manual_gcal_booking_order_status', 'bkap_manual_gcal_booking_order_status', 8, 1 ); | |
function bkap_booking_pending_to_confirmed( $order_id, $old_status, $new_status ) { | |
if ( 'failed' !== $old_status && in_array( $new_status, array( 'processing' ), true ) ) { | |
$order = wc_get_order( $order_id ); | |
$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 ) && 'pending-confirmation' === $booking_status ) { | |
$status = 'confirmed'; | |
wc_update_order_item_meta( $item_key, '_wapbk_booking_status', $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( $status ); | |
$product_id = $item_value->get_product_id(); | |
bkap_insert_event_to_gcal( $order, $product_id, $item_key ); | |
} | |
} | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_changed', 'bkap_booking_pending_to_confirmed', 8, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment