gpb_capacity_limit
Description
Filter the capacity limit for a specific time period. This filter allows you to dynamically adjust capacity based on the booking date/time. Useful for scenarios like reduced weekend capacity, seasonal adjustments, or special events.
Usage
Applied globally
add_filter( 'gpb_capacity_limit', 'my_custom_function' );Parameters
$capacity
Capacity_Limit
The capacity limit.
$start_datetime
string
Start datetime of the booking (Y-m-d H:i:s format).
$end_datetime
string
End datetime of the booking (Y-m-d H:i:s format).
$bookable
object
The bookable object (Service or Resource).
Examples
Reduce capacity on weekends
add_filter( 'gpb_capacity_limit', function( $capacity, $start_datetime, $end_datetime, $bookable ) {
$day_of_week = CarbonCarbon::parse( $start_datetime )->dayOfWeek;
if ( $day_of_week === CarbonCarbon::SATURDAY || $day_of_week === CarbonCarbon::SUNDAY ) {
return GP_BookingsCapacityCapacity_Limit::limited( 5 );
}
return $capacity;
}, 10, 4 );Unlimited capacity on a specific date (e.g., grand opening)
add_filter( 'gpb_capacity_limit', function( $capacity, $start_datetime, $end_datetime, $bookable ) {
$booking_date = CarbonCarbon::parse( $start_datetime )->format( 'Y-m-d' );
if ( $booking_date === '2024-06-15' ) { // Grand opening day
return GP_BookingsCapacityCapacity_Limit::unlimited();
}
return $capacity;
}, 10, 4 );Reduced capacity for long bookings (using both start and end)
add_filter( 'gpb_capacity_limit', function( $capacity, $start_datetime, $end_datetime, $bookable ) {
$start = CarbonCarbon::parse( $start_datetime );
$end = CarbonCarbon::parse( $end_datetime );
$duration_hours = $start->diffInHours( $end );
if ( $duration_hours > 2 ) {
return GP_BookingsCapacityCapacity_Limit::limited( 3 );
}
return $capacity;
}, 10, 4 );Since
1.0-beta-1.1Hook added.