Created
June 15, 2020 09:58
-
-
Save rajeshsingh520/f0e00b7cc0e52f24ddeac67ffcc2d0bd to your computer and use it in GitHub Desktop.
If time for today is less then 15:00 then all time slot will be avialbel for tomorrow, if it goes above 15:00 then only time slot with end time above 12:00 will be avialable for pickup
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 | |
| class pisol_axd659_next_day_cutoff{ | |
| function __construct($cutoff_time, $next_day_time){ | |
| $this->cutoff_time = $cutoff_time; | |
| $this->next_day_time = $next_day_time; | |
| add_filter('pisol_dtt_time_slot_filter', array($this, 'next_day_filter'),10, 2); | |
| } | |
| function next_day_filter($times, $date){ | |
| $type = pi_dtt_delivery_type::getType(); | |
| if($type === 'pickup'){ | |
| $current_date = current_time('Y/m/d'); | |
| $next_date = date('Y/m/d',strtotime($current_date.' + 1 days')); | |
| if($date == $next_date && $this->nextDayCutoffReached()){ | |
| foreach($times as $key => $time){ | |
| $end_time_of_time_slot = $this->pisolTimeForCompare($time['id']); | |
| $end_time_of_time_slot_timestamp = strtotime($end_time_of_time_slot); | |
| $next_day_time_timestamp = strtotime($this->next_day_time); | |
| if($next_day_time_timestamp >= $end_time_of_time_slot_timestamp){ | |
| unset($times[$key]); | |
| } | |
| } | |
| return array_values($times); | |
| } | |
| } | |
| return $times; | |
| } | |
| function nextDayCutoffReached(){ | |
| $current_time = current_time("H:i"); | |
| $current_timestamp = strtotime($current_time); | |
| $cutoff_timestamp = strtotime($this->cutoff_time); | |
| if($current_timestamp >= $cutoff_timestamp){ | |
| return true; | |
| } | |
| return false; | |
| } | |
| function pisolTimeForCompare($time){ | |
| if(strpos($time, '-') !== false){ | |
| $times_array = explode("-",$time); | |
| return isset($times_array[1]) ? trim($times_array[1]) : $times_array[0]; | |
| }else{ | |
| return trim($time); | |
| } | |
| return null; | |
| } | |
| } | |
| new pisol_axd659_next_day_cutoff('15:00', '12:00'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment