gpb_availability_blocks

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Inject a one-off negative block for a specific resource.

Description

Filter the availability blocks for a bookable. Allows virtual blocks to be injected at read time without persisting them to the database.

Usage

Applied globally

add_filter( 'gpb_availability_blocks', 'my_custom_function' );

Parameters

$blocks AvailabilityBlock[]

The availability blocks.

$bookable Bookable

The bookable (Service or Resource).

Examples

Inject a one-off negative block for a specific resource.

add_filter( 'gpb_availability_blocks', function ( $blocks, $bookable ) {
    if ( ! $bookable instanceof GP_BookingsResource || $bookable->get_id() !== 42 ) {
        return $blocks;
    }
    $blocks[] = new GP_BookingsAvailabilityBlock( [
        'object_id'         => $bookable->get_id(),
        'object_type'       => 'resource',
        'availability_days' => [],
        'start_date'        => '2026-05-01',
        'end_date'          => '2026-05-01',
        'start_time'        => '09:00:00',
        'end_time'          => '12:00:00',
        'is_negative'       => true,
    ], $bookable );
    return $blocks;
}, 10, 2 );