PluginProbe ʕ •ᴥ•ʔ
PiWeb Delivery & Pickup Date Time for WooCommerce / 3.0.49.3
PiWeb Delivery & Pickup Date Time for WooCommerce v3.0.49.3
3.0.63 3.0.62 3.0.61 3.0.60 3.0.49.49 3.0.49.6 3.0.49.60 3.0.49.61 3.0.49.62 3.0.49.63 3.0.49.64 3.0.49.66 3.0.49.67 3.0.49.69 3.0.49.7 3.0.49.70 3.0.49.72 3.0.49.73 3.0.49.74 3.0.49.76 3.0.49.77 3.0.49.79 3.0.49.9 3.0.49.90 3.0.49.91 3.0.49.92 3.0.49.93 3.0.49.94 3.0.49.96 3.0.49.97 3.0.49.99 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 2.9.17 3.0.47 3.0.49 3.0.49.1 3.0.49.10 3.0.49.11 3.0.49.12 3.0.49.13 3.0.49.16 3.0.49.17 3.0.49.19 3.0.49.2 3.0.49.20 3.0.49.21 3.0.49.22 3.0.49.23 3.0.49.24 3.0.49.26 3.0.49.27 3.0.49.29 3.0.49.3 3.0.49.30 3.0.49.31 3.0.49.32 3.0.49.33 3.0.49.34 3.0.49.36 3.0.49.37 3.0.49.39 3.0.49.4 3.0.49.40 3.0.49.41 3.0.49.42 3.0.49.43 3.0.49.44 3.0.49.46 3.0.49.47
pi-woocommerce-order-date-time-and-type / public / class-time-slot.php
pi-woocommerce-order-date-time-and-type / public Last commit date
css 2 years ago js 2 years ago class-css.php 2 years ago class-date.php 2 years ago class-delivery-type.php 2 years ago class-display-field.php 2 years ago class-js.php 2 years ago class-main.php 2 years ago class-order.php 2 years ago class-pickup-location.php 2 years ago class-shipping-method.php 2 years ago class-time-range.php 2 years ago class-time-slot.php 2 years ago class-time.php 2 years ago class-validate.php 2 years ago class-woo-app.php 2 years ago
class-time-slot.php
156 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pisol_dtt_time_slot{
6
7 public $selected_date;
8 public $delivery_type;
9 public $day;
10 public $time_slot;
11
12 function __construct($selected_date){
13 $this->selected_date = $selected_date;
14 }
15
16 static function getTimeSlotArray( $date, $type = "" ){
17 $obj = new self($date);
18 $time_slot = $obj->init($type);
19 return $time_slot;
20 }
21
22 static function getTimeSlotJson($date, $type = "" ){
23 $obj = new self($date);
24 $obj->getTime($type);
25 }
26
27 function getTime($type = ""){
28 $time_slot = $this->init($type);
29 echo json_encode($time_slot);
30 die;
31 }
32
33 function init($type = ""){
34
35 if(empty($this->selected_date)) return array();
36 if(empty($type)){
37 $this->delivery_type = pi_dtt_delivery_type::getType();
38 }else{
39 $this->delivery_type = $type;
40 }
41
42 $this->day = strtolower(pisol_dtt_time::dayOfTheWeek( $this->selected_date ));
43 $this->time_slot = $this->getTimeSlot($this->day, $this->delivery_type);
44 return apply_filters('pisol_dtt_time_slot_filter',$this->time_slot, $this->selected_date, $this->delivery_type);
45 }
46
47 function getTimeSlot($day, $delivery_type){
48
49 $forced_time_slots = apply_filters('pisol_forced_valid_time_slots',null, $day, $this->selected_date, $delivery_type);
50 if($forced_time_slots !== null && is_array($forced_time_slots)) return $forced_time_slots;
51
52 $slots = $this->getGeneralTimeSlots( $delivery_type );
53
54 $slots = apply_filters('pisol_dtt_forced_time_slots', $slots, $day, $this->selected_date, $delivery_type);
55
56 return $this->filterSlots($slots);
57 }
58
59 function getGeneralTimeSlots( $delivery_type ){
60 $slots = pisol_dtt_get_setting('pi_general_time_slot_'.$delivery_type, array());
61 if(empty($slots)) return array();
62
63 return $slots;
64 }
65
66 function filterSlots($slots){
67 if(empty($slots)) return array();
68
69 $return1 = $this->removePastTime($slots);
70
71 $return2 = $this->customFilter($return1);
72
73 $return3 = $this->convertToString($return2);
74
75 return $return3;
76 }
77
78 static function slotToString($slot){
79 $key = pisol_dtt_time::formatTimeForStorage($slot['from']).' - '.pisol_dtt_time::formatTimeForStorage($slot['to']);
80 return $key;
81 }
82
83
84 function removePastTime($time_array){
85
86
87 if(!is_array($time_array) || $time_array == ""){
88 return "";
89 }
90
91 if(!$this->isSelectedDateToday()) return $time_array;
92
93 $order_preparation_time = pisol_dtt_get_setting('pi_order_preparation_hours',60);
94 $order_preparation_time = $order_preparation_time == "" ? 0 : $order_preparation_time;
95
96 $now = current_time('h:i A');
97
98 $minutes_to_add = "+".$order_preparation_time." minutes";
99
100 $time_limit = strtotime($minutes_to_add, strtotime($now));
101 foreach($time_array as $key => $time){
102 if($time['to'] != ""){
103 if(strtotime($time['to']) < $time_limit){
104 unset($time_array[$key]);
105 }
106 }else{
107 if($time['from'] != ""){
108 if(strtotime($time['from']) < $time_limit){
109 unset($time_array[$key]);
110 }
111 }
112 }
113 }
114 return $time_array;
115 }
116
117 function customFilter($return){
118 return apply_filters("pisol_dtt_custom_remove_time_slots", $return, $this->selected_date);
119 }
120
121 function isSelectedDateToday(){
122 $today = current_time('Y/m/d');
123 if($this->selected_date == $today){
124 return true;
125 }
126 return false;
127 }
128
129 function convertToString($slots){
130 $return = array();
131 if(!empty($slots)){
132 foreach($slots as $slot){
133 $key = pisol_dtt_time::formatTimeForStorage($slot['from']).' - '.pisol_dtt_time::formatTimeForStorage($slot['to']);
134
135 $value = self::removeEmptyTimeFromDisplay(pisol_dtt_time::formatTimeForDisplay($slot['from']), pisol_dtt_time::formatTimeForDisplay($slot['to']));
136 $return[] = array('id'=>$key, 'text'=>$value);
137 }
138 }
139 return $return;
140 }
141
142 static function removeEmptyTimeFromDisplay($from, $to){
143 if(!empty($from) && !empty($to)){
144 return $from.' - '.$to;
145 }
146
147 if(!empty($from) && empty($to)){
148 return $from;
149 }
150
151 if(empty($from) && !empty($to)){
152 return $to;
153 }
154 return "";
155 }
156 }