Custom Validation Rules
You can use the Booking Restrictions add-on to set up some pretty complex booking validation rules, but sometimes there are not enough. You can always create your own by adding some code in your theme’s functions.php file.
Date Validation
This is fired after a date is selected, showing an error message below the calendar if the date selection is invalid. The filter accepts 2 parameters and returns an array.
Syntax
add_filter('wpbs_date_validation', 'your_function', 10, 2);
or
add_filter('wpbs_date_validation_{form_id}', 'your_function', 10, 2);
Examples
1. Force the starting date to be on the 10th of the month.
2. Allow a booking from Monday to Friday or Sunday or from Friday to Sunday.
Field Validation
This is fired after the form is submitted and can be used to validate the value of a form field. The filter accepts 2 parameters and returns an array.
Syntax
add_filter('wpbs_field_validation', 'your_function', 10, 2);
or
add_filter('wpbs_field_validation_{form_id}', 'your_function', 10, 2);
or
add_filter('wpbs_field_validation_{form_id}_{field_id}', 'your_function', 10, 2);
Examples
1. Check if the value of a field is lower than 5.
Form Validation
This is fired after the form is submitted and can be used to validate multiple fields at once and compare their values. The filter accepts 2 parameters and returns an array.
Syntax
add_filter('wpbs_form_validation', 'your_function', 10, 2);
or
add_filter('wpbs_form_validation_{form_id}', 'your_function', 10, 2);
Examples
1. Check if two email addresses match. You will need to add two Email form fields to your form. Notice the field IDs in the foreach loop, you will have to update these to match your form’s field IDs.
2. Validate the total number of people from two different fields, eg. adults and children. Notice the field IDs in the foreach loop, you will have to update these to match your form’s field IDs.