<?php
/**
* Gravity Perks // GP Limit Dates // Block Date Ranges via Exceptions
*/
add_filter( 'gpld_limit_dates_options_FORMID_FIELDID', 'gpld_except_date_ranges', 10, 3 );
function gpld_except_date_ranges( $options, $form, $field ) {
/**
* Format: Start Date, End Date
*/
$ranges = array(
array( '2016-07-15', '2017-01-01' ),
array( '2020-12-10', '2020-12-20' ),
);
// do not modify below this line
foreach ( $ranges as $range ) {
$start_date = new DateTime( $range[0] );
$end_date = new DateTime( $range[1] );
// include end date.
$end_date->setTime( 0, 0, 1 );
$period = new DatePeriod( $start_date, new DateInterval( 'P1D' ), $end_date );
foreach ( $period as $date ) {
$options['exceptions'][] = $date->format( 'm/d/Y' );
}
}
$options['exceptionMode'] = 'disable';
return $options;
}
I use this snippet and it works fine, but now I would like to leave out a single date picker field in a single form?
Hi Jesper,
This snippet is already designed to target specific date fields, so I’m not entirely sure how you’re currently applying it. Could you clarify how you’re using the snippet? Also, is this question related to the ticket you submitted about the universal exception snippet, or is it a separate issue?
Best,
How can I create and use a {weekends_minus_exceptions} and {weedayss_minus_exceptions} merge tag in Gravity Forms that automatically counts the number of weekend and weekday days between a Start Date and End Date, while excluding any dates listed as exceptions? The exception dates already selected in Start Date and End Date date picker.
Hi Fiqri,
We don’t currently have a built-in solution for this, but it may be possible to achieve with a custom snippet. Our Pro license includes support for minor customizations, so if you have a Pro license, please submit a ticket we can take a closer look and assist you with the custom snippet.
Best,