Created
          November 28, 2024 11:19 
        
      - 
      
- 
        Save pramodjodhani/e81e471e765b6b9600e9bd6fbeb1dc26 to your computer and use it in GitHub Desktop. 
    Iconic WDS - Remove dates after a certain date.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?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