I am trying to limit the availability of the resources so that they can be booked only once per day.
Ex: Opening times: 9am to 1pm. If a resource is booked Monday, from 10am to 1pm, it should not be possible to book the resource from 9am to 10am.
This is what I have done so far, which is working for products with only 1 resource available:
$fullObj = array();
foreach ( $existing_bookings as $existing_booking ) {
if ( ! is_a( $existing_booking, 'WC_Booking' ) ) {
continue;
}
// echo '<pre>';
// print_r($existing_booking);
// echo'</pre>';
$InnerObj = array();
$dateObj = array();
$res = array();
$InnerObj['person_counts'] = $existing_booking->get_person_counts()[0];
$InnerObj['order_id'] = $existing_booking->get_order_id();
$InnerObj['resource_id'] = $existing_booking->get_resource_id();
$InnerObj['resource_order_id'] = $existing_booking->ID;
$InnerObj['date_created'] = date('Y-m-d', $existing_booking->get_date_created());
$InnerObj['date_modified'] = date( 'Y-m-d', $existing_booking->get_start() );
$InnerObj['end'] = date( 'Y-m-d', $existing_booking->get_end() );
$res[$existing_booking->get_resource_id()] = 1;
$dateObj[date( 'Y-m-d', $existing_booking->get_start() )] = $res;
//array_push($booked_day_blocks['fully_booked_days'], $dateObj);
$date_format = date( 'Y-n-j', $existing_booking->get_start() );
$booked_day_blocks[ 'fully_booked_days' ][ $date_format ][ $existing_booking->get_resource_id() ] = 1;
}
However, if the product has more than 1 resource available, it doesn’t take it into consideration, and the day is marked as fully booked, when it should only be so when the last resource available has been booked.
Thanks!
eirem151 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.