gpb_availability_start

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Restrict bookings to start 3 days from now
    2. Restrict bookings for specific service
    3. Restrict bookings when specific resource is selected
  5. Since

Description

Filter the start date for availability checks. This filter allows you to set an absolute minimum date for bookings. Any dates before this will be marked as unavailable in REST responses and rejected during booking validation. Return null to allow bookings from today onwards (no restriction outside of Availability Windows).

Usage

Filter applied globally to all availability checks

add_filter( 'gpb_availability_start', 'my_custom_function' );

Parameters

$start CarbonImmutable|null

Start date (null = no restriction).

$service Service

Service object.

$resource_ids int[]

Resource IDs being checked.

Examples

Restrict bookings to start 3 days from now

Prevent same-day or next-day bookings by requiring at least 3 days advance notice.

add_filter( 'gpb_availability_start', function( $start, $service, $resource_ids ) {
    return \Carbon\CarbonImmutable::today()->addDays( 3 );
}, 10, 3 );

Restrict bookings for specific service

Only apply the restriction to a specific service (ID 123).

add_filter( 'gpb_availability_start', function( $start, $service, $resource_ids ) {
    if ( $service->get_id() === 123 ) {
        return \Carbon\CarbonImmutable::today()->addWeeks( 2 );
    }
    return $start;
}, 10, 3 );

Restrict bookings when specific resource is selected

Apply different restrictions based on which resource is being booked.

add_filter( 'gpb_availability_start', function( $start, $service, $resource_ids ) {
    // Premium resource requires 1 week advance notice
    if ( in_array( 456, $resource_ids ) ) {
        return \Carbon\CarbonImmutable::today()->addWeeks( 1 );
    }
    return $start;
}, 10, 3 );

Since

  • 1.0-alpha-4.2 Hook added.