Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active April 14, 2025 07:57
Show Gist options
  • Save Crocoblock/54462e609349358a9602a8cc9688e339 to your computer and use it in GitHub Desktop.
Save Crocoblock/54462e609349358a9602a8cc9688e339 to your computer and use it in GitHub Desktop.
JetBooking / Exclude posts that are unavailable on check-in and check-out dates
<?php
add_filter( 'jet-smart-filters/query/final-query', function( $query ) {
if ( empty( $query['meta_query'] ) ) {
return $query;
}
$store_type = jet_abaf()->settings->get( 'filters_store_type' );
foreach ( $query['meta_query'] as $index => $meta_query ) {
if ( isset( $meta_query['key'] ) && ( 'chekin_checkout' === $meta_query['key'] || 'checkin_checkout' === $meta_query['key'] ) ) {
[ $from, $to ] = $query['jet_booking_period'] = $meta_query['value'];
unset( $query['meta_query'][ $index ] );
jet_abaf()->stores->get_store( $store_type )->set( 'searched_dates', $from . ' - ' . $to );
$hours = jet_abaf()->settings->is_per_nights_booking() ? 24 : 12;
$exclude_in = jet_abaf()->tools->get_unavailable_apartments( $from, $from + $hours * HOUR_IN_SECONDS );
$exclude_out = jet_abaf()->tools->get_unavailable_apartments( $to, $to + $hours * HOUR_IN_SECONDS );
$exclude = array_merge( $exclude_in, $exclude_out );
if ( $exclude ) {
$query['post__not_in'] = $exclude;
}
}
}
return $query;
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment