I'm trying to use the function check_availability_rules_against_time
on WooCommerce Bookings to determine if a range of time is available for accomodation. As I understand, it should return true if the time slot checked against the rules is available. The problem I have is that it returns true if the start time is available, even if the slot goes beyond the availavility range.
For example, I have this ranges on a product:
So I test it like this:
<?php
// Query Filter
$args = array(
'post_type' => 'product',
'posts_per_page' => 20,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $hotel['cat_habitaciones'],
'operator' => 'IN'
))
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
if( ! $product->has_resources() || count($product->get_resources()) == 0 ){
continue;
}
foreach($product->get_resources() as $resource){
echo (WC_Product_Booking_Rule_Manager::check_availability_rules_against_time('2020-04-01','2020-07-01',$resource->id,$product,true)) ? 'Available' : 'Not Available';
}
?>
...html...
<?php
endwhile;
} else {
echo __( 'No se encontraron habitaciones disponibles.' );
}
wp_reset_postdata();
So, this code in the above product should return false, because acording to the rules it stops being bookable in may, but it still returns true. If I move the start day to may, it will correctly return false.
Can you help me get what I'm doing wrong?