Created
November 2, 2022 17:19
-
-
Save kartikparmar/0a9dcc195060a5d531cedf4db3c8734a to your computer and use it in GitHub Desktop.
Global Time Slots Booking for the Durations Based Time
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 | |
/** | |
* Global Time Slots Booking for the Durations Based Time. | |
*/ | |
function bkap_additional_bookings_to_be_considered( $booking_idss, $product_id, $resource_id ) { | |
// Getting Product ids that has Duration Based Time Booking Type. | |
$args = array( | |
'post_type' => 'product', | |
'meta_query' => array( | |
array( | |
'key' => '_bkap_booking_type', | |
'value' => 'duration_time', | |
'compare' => '=', | |
), | |
), | |
); | |
$duration_query = new WP_Query( $args ); | |
$product_ids = array(); | |
if ( $duration_query->have_posts() ) { | |
foreach ( $duration_query->posts as $post1 ) { | |
$product_ids[] = $post1->ID; | |
} | |
if ( ( $key = array_search( $product_id, $product_ids ) ) !== false ) { | |
unset( $product_ids[ $key ] ); | |
} | |
} | |
if ( $resource_id > 0 ) { | |
$meta_key = '_bkap_resource_id'; | |
$meta_value = $resource_id; | |
} else { | |
$meta_key = '_bkap_product_id'; | |
$meta_value = $product_id; | |
} | |
if ( count( $product_ids ) > 0 ) { | |
// IF there are other products that are setup with the Duration Based Time Booking Type | |
// Then fetch the bookings of those products and consider those bookings for current product. | |
$args = array( | |
'post_type' => 'bkap_booking', | |
'post_status' => array( 'paid', 'pending-confirmation', 'confirmed' ), | |
'posts_per_page' => -1, | |
'meta_query' => array( | |
array( | |
'key' => $meta_key, | |
'value' => $product_ids, | |
'compare' => 'IN', | |
), | |
), | |
); | |
$query1 = new WP_Query( $args ); | |
if ( $query1->have_posts() ) { | |
foreach ( $query1->posts as $post1 ) { | |
$booking_idss[] = $post1->ID; | |
} | |
} | |
} | |
return $booking_idss; | |
} | |
add_filter( 'bkap_additional_bookings_to_be_considered', 'bkap_additional_bookings_to_be_considered', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment