- 28 Sep 2022
- 1 Minute to read
Prevent product purchases if a booking is shorter than a set amount of time
- Updated on 28 Sep 2022
- 1 Minute to read
This rule prevents the purchase of a specific product alongside a booking if the booking is shorter than a minimum length you define.
For example, customers booking any resource for less than 2 hours cannot purchase the catering service that you sell as a product alongside the resource.
You need the following details to set up this rule:
- The ID of the product that can't be purchased if bookings are too short.
Check out our tutorial on Finding Product IDs.
Log in to the Admin Panel if you aren't already.
Click Settings > Validation rules.
Click Add rule.
Click on Manual entry.
Name your validation rule.
Add a Description for your rule to let other admins know what it does at a glance.
Enable the This rule is active toggle.
Select Bookings in the Record type.
Add the Error message to display if the validation rule is not met.
Add the following code snippet to the Formula field.
(record.GetLengthInMinutes() >= MINUTES) OR (HasProduct(record, PRODUCT_ID) = false)
- Replace MINUTES in the formula with the minimum booking length to allow the purchase of the selected products.
In the example below we used 2 hours or 120 minutes.
(record.GetLengthInMinutes() >= 120) OR (HasProduct(record, PRODUCT_ID) = false)
- Replace PRODUCT_ID in the formula with the ID of the product that can't be purchased if bookings don't meet the mimimum length defined in the previous step.
In the example below, the product ID is 123456789.
(record.GetLengthInMinutes() >= 120) OR (HasProduct(record, 123456789) = false)
Click the Save Changes button.
All done! We recommend you test your validation rule by trying to purchase the selected product alongside a booking that is shorter than the minimum booking length defined in your rule. If you get the error message you've defined, your rule is ready to go!