gpb_capacity_bookings

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Count fixed shifts independently for a specific resource.

Description

Filter the bookings used to calculate remaining capacity. Runs after pending/confirmed status and booking exclusions are applied, before measuring peak concurrent usage. Datetimes are in the site’s timezone. Does not run for unlimited capacity. Return an array of booking row objects; a non-array return falls back to the original bookings. This affects callers of get_remaining_capacity(), including slot availability and booking validation. It does not change availability blocks or buffer rules.

Usage

Applied globally

add_filter( 'gpb_capacity_bookings', 'my_custom_function' );

Parameters

$booked array<object>

Rows containing start_datetime, end_datetime and quantity.

$start_datetime string

Start of the requested range (Y-m-d H:i:s).

$end_datetime string

End of the requested range (Y-m-d H:i:s).

$bookable GP_BookingsBookable

The service or resource whose capacity is being checked.

$exclude_booking_id int|null

Booking ID excluded from the calculation, if any.

Examples

Count fixed shifts independently for a specific resource.

add_filter( 'gpb_capacity_bookings', function( $bookings, $start, $end, $bookable ) {
    if ( ! $bookable instanceof GP_BookingsResource || $bookable->get_id() !== 123 ) {
        return $bookings;
    }
    return array_values( array_filter( $bookings, static function( $booking ) use ( $start, $end ) {
        return $booking->start_datetime === $start && $booking->end_datetime === $end;
    } ) );
}, 10, 4 );