The JetAppointment plugin for WordPress is a powerful tool for managing bookings and appointments. However, one common limitation developers encounter is the maximum “Locked Time Before” or “buffer period” before an appointment, which defaults to 24 hours. This means you can’t prevent users from booking an appointment, say, less than 3 days or even a month in advance directly through the plugin settings.
Table of Contents
If you’ve found yourself needing to set a longer booking buffer – perhaps your services require significant preparation time, or you need to prevent last-minute bookings for logistical reasons – you’re in the right place. This guide will walk you through a PHP code snippet that uses a WordPress filter hook to extend this lock time to any duration you need.
The Challenge: JetAppointment’s Default “Locked Time Before”

Out of the box, JetAppointment allows you to set a “Lock time before booking” in hours. While useful for preventing same-day or very short-notice bookings, it doesn’t cater to scenarios where a longer lead time is necessary. Trying to input a value greater than 24 hours (or its equivalent in minutes/days depending on the UI) usually doesn’t work as expected.
The Solution: Using the jet-apb/calendar/custom-schedule
Filter
Fortunately, JetAppointment provides a handy filter hook, jet-apb/calendar/custom-schedule
, that allows developers to programmatically modify the schedule data, including “days off” or buffer periods. We can leverage this to inject our custom, extended lock time.
The Code
Here’s the PHP snippet that achieves this:
add_filter( 'jet-apb/calendar/custom-schedule', function( $value, $meta_key, $default_value, $provider, $service ) {
if ( $meta_key === 'days_off' ) {
$buffer_days = 30; // This value sets the number of days to prevent booking
$buffer_period = array (
'start' => date( 'd-m-Y', strtotime( 'today' ) ),
'startTimeStamp' => strtotime( 'today' ) * 1000,
'end' => date( 'd-m-Y', strtotime( sprintf( "today+%sdays", $buffer_days ) ) ),
'endTimeStamp' => strtotime( sprintf( "today+%sdays", $buffer_days ) ) * 1000,
'name' => 'buffer',
'type' => 'days_off',
'editIndex' => '',
);
// Ensure $value is an array before appending the new buffer period.
// This prevents the "Cannot access offset of type string on string" error.
if (! is_array( $value ) ) {
$value = [];
}
$value[] = $buffer_period;
}
return $value;
}, 0, 5 );
Code Breakdown:
add_filter( 'jet-apb/calendar/custom-schedule', function( ... ), 10, 5 );
- This is the standard WordPress way to hook into a filter.
'jet-apb/calendar/custom-schedule'
: The specific JetAppointment filter we’re using.function( $value, $meta_key, $default_value, $provider, $service ) { ... }
: Our custom callback function. It receives five arguments:$value
: The current value of the schedule meta (e.g., an array of days off). This is what we’ll modify.$meta_key
: The specific piece of schedule data being processed (e.g., ‘days_off’, ‘working_hours’).$default_value
: The default value for this meta key.$provider
: The current provider object or ID.$service
: The current service object or ID.
10
: The priority of our filter (standard default).5
: The number of arguments our function accepts.
if ( $meta_key === 'days_off' ) { ... }
- This conditional check ensures our logic only runs when the filter is processing the
days_off
data. We want to add our buffer as a “day off.”
- This conditional check ensures our logic only runs when the filter is processing the
$buffer_days = 30;
- This is the line you’ll most likely want to customize. It sets how many days from today will be blocked for booking. In this example, it’s 30 days. If you want to block bookings for the next 7 days, you would set this to
7
.
- This is the line you’ll most likely want to customize. It sets how many days from today will be blocked for booking. In this example, it’s 30 days. If you want to block bookings for the next 7 days, you would set this to
$buffer_period = array ( ... );
- This array defines the actual date range to be blocked.
'start'
: The start date of the buffer period, formatted as ‘d-m-Y’.strtotime('today')
gets the beginning of the current day.'startTimeStamp'
: The start timestamp in milliseconds, as JetAppointment often uses this format internally.'end'
: The end date of the buffer period.sprintf( "today +%d days", $buffer_days - 1 )
calculates the date X days from today. We use$buffer_days - 1
becausestrtotime("today +0 days")
is today, so if you want a 1-day buffer (today), it’s+0 days
. If you want a 30-day buffer (today + next 29 days), it’s+29 days
.'endTimeStamp'
: The end timestamp in milliseconds.'name'
: A descriptive name. This might appear in debug logs or internal data structures.'type'
: Crucially set to'days_off'
. This tells JetAppointment to treat this period as unavailable.'editIndex'
: Usually left empty for programmatically added periods.
if ( ! is_array( $value ) ) { $value = []; }
- This is an important safeguard. The
$value
passed to the filter might sometimes not be an array (e.g., if no “days off” are set yet, it could benull
or an empty string depending on the plugin’s internal state). Attempting to use array syntax like$value[]
on a non-array will cause a PHP error (“Cannot use [] for reading” or “Cannot access offset of type string on string”). This line ensures$value
is always an array, initializing it as empty if necessary.
- This is an important safeguard. The
$value[] = $buffer_period;
- This line appends our newly defined
$buffer_period
to the array of existing “days off.”
- This line appends our newly defined
return $value;
- The filter must return the modified
$value
so JetAppointment can use it.
- The filter must return the modified
How to Implement This Code
You have a couple of common options for adding this PHP snippet to your WordPress site:
- Child Theme’s
functions.php
file: This is often the recommended method for theme-related customizations. If you’re using a child theme, simply open itsfunctions.php
file and paste this code at the end. - Custom Plugin: For better organization and to keep functionality separate from your theme, you can create a simple custom plugin. Create a new PHP file (e.g.,
my-jetappointment-mods.php
) in yourwp-content/plugins/
directory, add the standard plugin header, and then paste the code.<?php /** * Plugin Name: My JetAppointment Customizations * Description: Extends JetAppointment booking lock time. * Version: 1.0 * Author: Your Name */ // Prevent direct access if ( ! defined( 'ABSPATH' ) ) { exit; } add_filter( 'jet-apb/calendar/custom-schedule', function( $value, $meta_key, $default_value, $provider, $service ) { // ... (rest of the code from above) }); ?>
Then, activate this plugin from your WordPress admin panel.
Important: Always back up your site before adding custom code. If you’re not comfortable editing PHP files, consider consulting with a developer.
Customizing the Lock Time
To change the duration of the booking lock:
- Locate the line:
$buffer_days = 30;
- Change
30
to your desired number of days. For instance, for a 1-week (7 days) buffer, you would use:$buffer_days = 7;
- For a 2-month (approx. 60 days) buffer:
$buffer_days = 60;
The code will then dynamically block out the period from today up to $buffer_days - 1
in the future.
Conclusion
By using the jet-apb/calendar/custom-schedule
filter, you can effectively overcome JetAppointment’s default 24-hour lock time limitation. This snippet provides a flexible way to define a custom buffer period, ensuring that you have the necessary lead time for your services.
This approach keeps your customizations cleanly separated from the core plugin files, making it a robust solution that should persist through plugin updates.
Happy coding! We hope this helps other developers looking to achieve similar functionality with JetAppointment.