Even Dates Only

Code

Filename: gpld-even-dates-only.php

<?php
/**
 * Gravity Perks // Limit Dates // Even Dates Only
 * https://gravitywiz.com/documentation/gravity-forms-limit-dates/
 */
// Update "123" to your form ID and "4" to your Date field ID.
add_filter( 'gpld_limit_dates_options_123_4', function( $field_options, $form, $field ) {
	if ( $field_options['minDate'] && $field_options['maxDate'] ) {

		$min_date = ( new DateTime() )->modify( $field_options['minDateMod'] );
		$max_date = ( new DateTime() )->modify( $field_options['maxDateMod'] );

		$even_days = array();

		while ( $min_date <= $max_date ) {
			if ( $min_date->format( 'd' ) % 2 !== 0 ) {
				$even_days[] = $min_date->format( 'm/d/Y' );
			}
			$min_date->modify( '+1 day' );
		}

		$field_options['exceptions'] = $even_days;

	}
	return $field_options;
}, 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.