Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created November 28, 2024 11:19
Show Gist options
  • Save pramodjodhani/e81e471e765b6b9600e9bd6fbeb1dc26 to your computer and use it in GitHub Desktop.
Save pramodjodhani/e81e471e765b6b9600e9bd6fbeb1dc26 to your computer and use it in GitHub Desktop.
Iconic WDS - Remove dates after a certain date.
<?php
/**
* Iconic WDS - Remove dates after a certain date.
*
* @param array $available_dates The available dates.
* @param string $format The format.
* @param bool $ignore_slots Ignore slots.
*
* @return array
*/
function iconic_wds_remove_dates_after_date( $available_dates, $format, $ignore_slots ) {
// if date is more than 31st of december 2024, remove it.
$max_date = new DateTime( '2024-12-31' );
foreach ( $available_dates as $key => $date ) {
if ( 'array' === $format ) {
$date = DateTime::createFromFormat( 'Ymd', $date['ymd'] );
} else {
$date = DateTime::createFromFormat( $format, $date );
}
if ( $date > $max_date ) {
unset( $available_dates[ $key ] );
}
}
return $available_dates;
}
add_filter( 'iconic_wds_available_dates', 'iconic_wds_remove_dates_after_date', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment