Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajeshsingh520/1c76ba1eafdc14269c21da2bb5760876 to your computer and use it in GitHub Desktop.
Save rajeshsingh520/1c76ba1eafdc14269c21da2bb5760876 to your computer and use it in GitHub Desktop.
product preparation time extended for more then 24 hr
<?php
/*
Plugin Name: Making 24hr time comparing for order date and time
*/
add_filter('pisol_dtt_time_slot_filter','pisol_small_addon_timeTo24Hour',10, 2);
add_filter('pisol_dtt_time_range_filter','pisol_small_addon_timeTo24Hour',10, 2);
function pisol_small_addon_timeTo24Hour($times, $date){
$current = current_time('Y/m/d H:i');
$preparation_minutes = pisol_dtt_get_setting('pi_order_preparation_hours',60);
$preparation_days = pisol_dtt_get_setting('pi_order_preparation_days',0);
$allowed_time = date('Y/m/d H:i',strtotime("+{$preparation_days} days {$preparation_minutes} minutes",strtotime($current)));
$allowed_timestamp = strtotime($allowed_time);
$new_time = array();
foreach($times as $key => $time){
$time_to_compare = pisol_small_addon_pisolTimeForCompare($time['id']);
$date_to_compare = $date.' '.$time_to_compare;
$timestamp_to_compare = strtotime($date_to_compare);
if($timestamp_to_compare > $allowed_timestamp){
$new_time[] = $times[$key];
}
}
return $new_time;
}
function pisol_small_addon_pisolTimeForCompare($time){
if(strpos($time, '-') !== false){
$times_array = explode("-",$time);
if(is_array($times_array)){
$times_array = array_map('trim', $times_array);
}
return isset($times_array[1]) && !empty($times_array[1]) ? trim($times_array[1]) : $times_array[0];
}else{
return trim($time);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment