PluginProbe ʕ •ᴥ•ʔ
PiWeb Delivery & Pickup Date Time for WooCommerce / 3.0.49.47
PiWeb Delivery & Pickup Date Time for WooCommerce v3.0.49.47
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.php
pi-woocommerce-order-date-time-and-type / public Last commit date
css 11 months ago js 11 months ago class-css.php 11 months ago class-date.php 11 months ago class-delivery-type.php 11 months ago class-display-field.php 11 months ago class-js.php 11 months ago class-main.php 11 months ago class-myaccount.php 11 months ago class-order.php 11 months ago class-pickup-location.php 11 months ago class-shipping-method.php 11 months ago class-time-range.php 11 months ago class-time-slot.php 11 months ago class-time.php 11 months ago class-validate.php 11 months ago class-woo-app.php 11 months ago
class-time.php
185 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pisol_dtt_time{
6
7 function __construct(){
8
9 add_action('wp_ajax_pisol_dtt_get_time', array($this,"getTime") );
10 add_action('wp_ajax_nopriv_pisol_dtt_get_time', array($this,"getTime") );
11
12 }
13
14 function getTime(){
15 if(!isset($_POST['selected_date'])) return;
16
17 $type = '';
18 if(isset($_POST['pi_dtt_delivery_type'])){
19 $type = sanitize_text_field($_POST['pi_dtt_delivery_type']);
20 }
21 /**
22 * have removed this check as we do validation of time slots as per date
23 * during checkout
24 */
25 /* if(!pi_dtt_date::isDateValid($_POST['selected_date'])) return; */
26
27 if(self::useTimeSlot()){
28 pisol_dtt_time_slot::getTimeSlotJson(sanitize_text_field($_POST['selected_date']), $type);
29 die;
30 }else{
31 pisol_dtt_time_range::getTimeRangeJson(sanitize_text_field($_POST['selected_date']), $type);
32 die;
33 }
34
35 }
36
37 static function getTimeArray($date, $type = ""){
38 $obj = new self();
39 if(!isset($date)) return;
40
41 if(!pi_dtt_date::isDateValid($date, $type)) return;
42
43 if(self::useTimeSlot($type)){
44 return pisol_dtt_time_slot::getTimeSlotArray($date, $type);
45 }else{
46 return pisol_dtt_time_range::getTimeRangeArray($date, $type);
47 }
48
49
50 }
51
52 static function isTimeValid($date, $input_time, $type = ""){
53
54 if(empty( $type )){
55 $type = pi_dtt_delivery_type::getType();
56 }else{
57 $type = $type;
58 }
59
60 $obj = new self();
61 if(!isset($date)) return false;
62
63 if(!pi_dtt_date::isDateValid($date, $type)) return false;
64
65 if(self::useTimeSlot($type)){
66 $time = pisol_dtt_time_slot::getTimeSlotArray($date, $type);
67 }else{
68 $time = pisol_dtt_time_range::getTimeRangeArray($date, $type);
69 }
70
71
72 if(empty($time)) return false;
73
74 $input_time = str_replace(' ', '', $input_time);
75
76 $time = str_replace(' ', '', array_column($time, 'id'));
77
78 if(array_search($input_time, $time) !== false) {
79 return true;
80 }
81
82 return false;
83
84
85 }
86
87 static function isTimeAvailable( $date ){
88 $time = array();
89
90 if(pi_dtt_display_fields::enableTimeField()){
91
92 if(self::useTimeSlot()){
93 $time = pisol_dtt_time_slot::getTimeSlotArray($date);
94 }else{
95 $time = pisol_dtt_time_range::getTimeRangeArray($date);
96 }
97
98 if( empty($time) ) return false;
99 }
100
101 return true;
102 }
103
104
105 static function dayOfTheWeek($date){
106 return strtolower(date("l",strtotime($date)));
107 }
108
109
110 static function formatTimeForDisplay($times){
111 $format = pisol_dtt_time::getDisplayFormat();
112 return pisol_dtt_time::formatTimeForStorage($times, $format);
113 }
114
115 static function formatTimeForStorage($times, $format = 'H:i'){
116 if(strpos($times,'-')){
117 $times_array = explode("-",$times);
118 }else{
119 $times_array[] = $times;
120 }
121
122 $formated_array = array();
123 foreach($times_array as $time){
124 $formated_array[] = strtotime(trim($time)) ? date($format, strtotime(trim($time))) : trim($time);
125 }
126 $return = "";
127 if(count($formated_array) == 2){
128 $return .= $formated_array[0].' - '.$formated_array[1];
129 }else{
130 $return .= $formated_array[0];
131 }
132 return $return;
133 }
134
135 static function getDisplayFormat(){
136 $format = pisol_dtt_get_setting('pi_time_format','h:mm p');
137
138 switch($format){
139 case 'h:mm p':
140 return "g:i A";
141 break;
142
143 case 'H:mm':
144 return "H:i";
145 break;
146
147 case 'H:mm p':
148 return "H:i A";
149 break;
150
151 default:
152 return "g:i A";
153 break;
154 }
155 }
156
157 static function useTimeSlot($type = ""){
158 if(empty($type)){
159 $type = pi_dtt_delivery_type::getType();
160 }
161 $user_setting = pisol_dtt_get_setting('pi_use_time_slot','all_slot');
162 switch($user_setting){
163 case 'all_slot':
164 return true;
165 break;
166
167 case 'all_range':
168 return false;
169 break;
170 case 'pickup_slot_delivery_range':
171 if($type == 'pickup') return true;
172
173 return false;
174 break;
175 case 'delivery_slot_pickup_range':
176 if($type == 'delivery') return true;
177
178 return false;
179 break;
180 }
181 return true;
182 }
183 }
184
185 new pisol_dtt_time();