PluginProbe ʕ •ᴥ•ʔ
PiWeb Delivery & Pickup Date Time for WooCommerce / 3.0.49.20
PiWeb Delivery & Pickup Date Time for WooCommerce v3.0.49.20
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 1 year ago js 1 year ago class-css.php 1 year ago class-date.php 1 year ago class-delivery-type.php 1 year ago class-display-field.php 1 year ago class-js.php 1 year ago class-main.php 1 year ago class-order.php 1 year ago class-pickup-location.php 1 year ago class-shipping-method.php 1 year ago class-time-range.php 1 year ago class-time-slot.php 1 year ago class-time.php 1 year ago class-validate.php 1 year ago class-woo-app.php 1 year ago
class-time-slot.php
155 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 }
31
32 function init($type = ""){
33
34 if(empty($this->selected_date)) return array();
35 if(empty($type)){
36 $this->delivery_type = pi_dtt_delivery_type::getType();
37 }else{
38 $this->delivery_type = $type;
39 }
40
41 $this->day = strtolower(pisol_dtt_time::dayOfTheWeek( $this->selected_date ));
42 $this->time_slot = $this->getTimeSlot($this->day, $this->delivery_type);
43 return apply_filters('pisol_dtt_time_slot_filter',$this->time_slot, $this->selected_date, $this->delivery_type);
44 }
45
46 function getTimeSlot($day, $delivery_type){
47
48 $forced_time_slots = apply_filters('pisol_forced_valid_time_slots',null, $day, $this->selected_date, $delivery_type);
49 if($forced_time_slots !== null && is_array($forced_time_slots)) return $forced_time_slots;
50
51 $slots = $this->getGeneralTimeSlots( $delivery_type );
52
53 $slots = apply_filters('pisol_dtt_forced_time_slots', $slots, $day, $this->selected_date, $delivery_type);
54
55 return $this->filterSlots($slots);
56 }
57
58 function getGeneralTimeSlots( $delivery_type ){
59 $slots = pisol_dtt_get_setting('pi_general_time_slot_'.$delivery_type, array());
60 if(empty($slots)) return array();
61
62 return $slots;
63 }
64
65 function filterSlots($slots){
66 if(empty($slots)) return array();
67
68 $return1 = $this->removePastTime($slots);
69
70 $return2 = $this->customFilter($return1);
71
72 $return3 = $this->convertToString($return2);
73
74 return $return3;
75 }
76
77 static function slotToString($slot){
78 $key = pisol_dtt_time::formatTimeForStorage($slot['from']).' - '.pisol_dtt_time::formatTimeForStorage($slot['to']);
79 return $key;
80 }
81
82
83 function removePastTime($time_array){
84
85
86 if(!is_array($time_array) || $time_array == ""){
87 return "";
88 }
89
90 if(!$this->isSelectedDateToday()) return $time_array;
91
92 $order_preparation_time = pisol_dtt_get_setting('pi_order_preparation_hours',60);
93 $order_preparation_time = $order_preparation_time == "" ? 0 : $order_preparation_time;
94
95 $now = current_time('h:i A');
96
97 $minutes_to_add = "+".$order_preparation_time." minutes";
98
99 $time_limit = strtotime($minutes_to_add, strtotime($now));
100 foreach($time_array as $key => $time){
101 if($time['to'] != ""){
102 if(strtotime($time['to']) < $time_limit){
103 unset($time_array[$key]);
104 }
105 }else{
106 if($time['from'] != ""){
107 if(strtotime($time['from']) < $time_limit){
108 unset($time_array[$key]);
109 }
110 }
111 }
112 }
113 return $time_array;
114 }
115
116 function customFilter($return){
117 return apply_filters("pisol_dtt_custom_remove_time_slots", $return, $this->selected_date);
118 }
119
120 function isSelectedDateToday(){
121 $today = current_time('Y/m/d');
122 if($this->selected_date == $today){
123 return true;
124 }
125 return false;
126 }
127
128 function convertToString($slots){
129 $return = array();
130 if(!empty($slots)){
131 foreach($slots as $slot){
132 $key = pisol_dtt_time::formatTimeForStorage($slot['from']).' - '.pisol_dtt_time::formatTimeForStorage($slot['to']);
133
134 $value = self::removeEmptyTimeFromDisplay(pisol_dtt_time::formatTimeForDisplay($slot['from']), pisol_dtt_time::formatTimeForDisplay($slot['to']));
135 $return[] = array('id'=>$key, 'text'=>$value);
136 }
137 }
138 return $return;
139 }
140
141 static function removeEmptyTimeFromDisplay($from, $to){
142 if(!empty($from) && !empty($to)){
143 return $from.' - '.$to;
144 }
145
146 if(!empty($from) && empty($to)){
147 return $from;
148 }
149
150 if(empty($from) && !empty($to)){
151 return $to;
152 }
153 return "";
154 }
155 }