Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created November 5, 2024 15:48
Show Gist options
  • Save kartikparmar/52334d10353a0f6f3c4205285329e822 to your computer and use it in GitHub Desktop.
Save kartikparmar/52334d10353a0f6f3c4205285329e822 to your computer and use it in GitHub Desktop.
Setting default booking status to pending confirmation
<?php
/**
* Change default booking status to confirmed when order is placed.
*
* @param string $status Status of Booking.
*/
function bkap_booking_status_on_create_order( $status ) {
return 'pending-confirmation';
}
add_filter( 'bkap_booking_status_on_create_order', 'bkap_booking_status_on_create_order', 10, 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