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-date.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-myaccount.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-date.php
173 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pi_dtt_date{
6
7 public $format;
8 public $type;
9 public $today;
10 public $preparation_days;
11 public $pre_order_days;
12 public $maxDays;
13 public $allowed_dates;
14 public $holidays;
15
16 function __construct( $type = "" ){
17 $this->format = 'Y/m/d';
18
19 if(empty( $type )){
20 $obj = new pi_dtt_delivery_type();
21 $this->type = $obj->getDeliveryType();
22 }else{
23 $this->type = $type;
24 }
25
26 $this->today = current_time($this->format);
27 $this->preparation_days = $this->preparationDaysCalculator();
28 $this->pre_order_days = empty(pisol_dtt_get_setting('pi_preorder_days', 10)) ? 0 : abs(pisol_dtt_get_setting('pi_preorder_days', 10));
29 $this->maxDays = $this->preparation_days + $this->pre_order_days;
30
31 $this->allowed_dates = $this->allowedDates($this->type);
32 $this->holidays = $this->getHolidays($this->type);
33 }
34
35 function preparationDaysCalculator(){
36 $preparation_days = (int)pisol_dtt_get_setting('pi_order_preparation_days',0);
37 return $preparation_days;
38 }
39
40 static function isDateValid($date, $type = ""){
41 $obj = new self($type);
42 $valid_dates = $obj->getValidDates();
43 if(in_array($date, $valid_dates)) return true;
44
45 return false;
46 }
47
48 function getValidDates(){
49 $valid_dates = array();
50
51 $forced_dates = apply_filters('pisol_forced_valid_dates',array(), $this->type);
52 if(!empty( $forced_dates )) return self::removeDatesOutSidePreparationTime($forced_dates);
53
54 for($i = $this->preparation_days; $i <= $this->maxDays; $i++){
55 $date = date($this->format, strtotime($this->today.' + '.$i.' days'));
56
57 if($this->nonWorkingDay($date)) continue;
58
59 if($this->isHoliday($date)) continue;
60
61 if($this->isTimeNotAvailable( $date )) continue;
62
63 $valid_dates[] = $date;
64 }
65
66 $valid_dates = apply_filters('pisol_valid_dates', $valid_dates, $this->type);
67 $valid_dates = self::removePastDates($valid_dates);
68 $valid_dates = self::removeDatesOutSidePreparationTime($valid_dates);
69 return is_array($valid_dates) ? array_values($valid_dates) : array();
70 }
71
72 function removeDatesOutSidePreparationTime($dates){
73 if(apply_filters('pisol_dtt_make_special_dates_not_follow_preparation_time',false)) return $dates;
74
75 $today = current_time('Y/m/d');
76 $today_timestamp = strtotime($today);
77 $first_allowed_date = date('Y/m/d', strtotime($today.' + '.$this->preparation_days.' days'));
78 foreach($dates as $key => $date){
79 if(strtotime($date) < strtotime($first_allowed_date)){
80 if(apply_filters('pisol_dtt_make_date_follow_preparation_time',true, $date, $this->preparation_days)){
81 unset($dates[$key]);
82 }
83 }
84 }
85
86 if(empty($dates)) return array();
87
88 return is_array($dates) ? array_values($dates) : array();
89 }
90
91 static function removePastDates($dates){
92 if(!is_array($dates)) array();
93 $today = current_time('Y/m/d');
94 $today_timestamp = strtotime($today);
95 $new_dates = array();
96 foreach($dates as $date){
97 if(!empty($date)){
98 $date_timestamp = strtotime($date);
99 if($date_timestamp >= $today_timestamp){
100 $new_dates[] = $date;
101 }
102 }
103 }
104 return $new_dates;
105 }
106
107 /**
108 * Handle once time class implemented
109 */
110 function isTimeNotAvailable( $date ){
111 return !pisol_dtt_time::isTimeAvailable( $date );
112 }
113
114 function nonWorkingDay($date){
115 $week = date('w', strtotime($date));
116 $allowed_days = $this->allowed_dates;
117 if(is_array($allowed_days) && in_array($week, $allowed_days)){
118 return false;
119 }
120 return true;
121 }
122
123 function allowedDates($type){
124 $var_name = 'pi_'.$type.'_days';
125 $allowed_days = pisol_dtt_get_setting($var_name, array());
126 if(empty( $allowed_days )){
127 return array(0,1,2,3,4,5,6);
128 }else{
129 return $allowed_days;
130 }
131 }
132
133 function isHoliday($date){
134 $holidays = $this->holidays;
135 if(is_array($holidays) && in_array($date,$holidays)){
136 return true;
137 }
138 return false;
139 }
140
141 function getHolidays($type){
142 $var_name = 'pisol_dtt_'.$type.'_dd';
143 $holidays = pisol_dtt_get_setting($var_name, array());
144 return $holidays;
145 }
146
147 static function formatedDate($date){
148 $format = pisol_dtt_get_setting('date_format','F j, Y');
149 $formated_date = strtotime($date) ? date($format, strtotime($date)) : $date;
150 return $formated_date;
151 }
152
153 static function translatedDate( $date ){
154 /**
155 * H:i:s is needed else it create different time stamp when time is missing
156 */
157 $original_timezone = date_default_timezone_get();
158 date_default_timezone_set( 'UTC' );
159 $date = str_replace( '/', '-', $date );
160 $datestamp = strtotime($date);
161 if($datestamp){
162 if(apply_filters('pi_dtt_bypass_date_i18n',false)){
163 $date = date(pisol_dtt_get_setting( 'date_format' ), $datestamp);
164 }else{
165 $date = date_i18n(pisol_dtt_get_setting( 'date_format' ), $datestamp);
166 }
167 date_default_timezone_set( $original_timezone );
168 return $date;
169 }
170 date_default_timezone_set( $original_timezone );
171 return $date;
172 }
173 }