spivurno
9/15/2016 - 3:33 PM

Gravity Perks // GP Limit Dates // Dynamically Enable Specific Dates

Gravity Perks // GP Limit Dates // Dynamically Enable Specific Dates

<?php
/**
 * Gravity Perks // GP Limit Dates // Dynamically Enable Specific Dates
 */
// replace "123" with your form ID, and "1" with your Date field ID
add_filter( 'gpld_limit_dates_options_123_1', 'gpld_dynamic_exceptions', 10, 3 );
function gpld_dynamic_exceptions( $options, $form, $field ) {

	$date_values = array( '2016-09-04', '2016-09-16', '2016-09-22', '2016-09-26' ); // replace with your own method for getting a date
	$max_date = time();

	foreach( $date_values as $date_value ) {
		$date_value = strtotime( $date_value );
		if( $date_value > $max_date ) {
			$options['exceptions'][] = date( 'm/d/Y', $date_value );
		}
	}

	$options['exceptionMode'] = 'enable';
	$options['disableAll'] = true;

	return $options;
}