Limited date availability (slots) for your WordPress booking form
Allow only a maximum amount of bookings (slots) for a specific date for your WordPress booking form. And display an error message when the date is fully booked and no longer available for selection.
Limit the amount of bookings for a specific date
// Return message if availability exceeded (date is fully booked)
add_action( 'super_before_sending_email_hook', 'f4d_check_availability', 1 );
function f4d_check_availability($x){
// Datepicker field name:
$fieldName = 'date'; // change this to your datepicker field name
$slots = 5; // allow 5 bookings for the same date in total
// Extract form data
extract(shortcode_atts(array('data'=>array()), $x));
$data = wp_unslash($data);
// Skip if field name does not exists
if(!isset($data[$fieldName])) return;
$date = trim(sanitize_text_field($data[$fieldName]['value']));
$msg = 'The selected date `'.$date.'` is fully booked! Please select a different date';
// Get the date slots, returns `0` if it doesn't exist yet
$slots = get_option('_sf_'.$fieldName.'_slots_' . $date, 0);
// Allow a maximum of 5 bookings for this date
if(absint($slots)>=10){
// Maximum is already reach return error message
echo json_encode(
array(
'error' => true,
'fields' => array($fieldName), // field that contains errors
'msg' => $msg
)
);
die();
}
// Continue as per usual with the form submission
$slots++;
update_option('_sf_'.$fieldName.'_slots_' . $date, $slots);
}
Increase availability after Contact Entry is deleted
Manually reset/set the availability for a specific date
PreviousDelete database row after contact entry is deleted in WordPressNextSend submitted form data to another site
Last updated