PluginProbe ʕ •ᴥ•ʔ
PiWeb Delivery & Pickup Date Time for WooCommerce / 3.0.62
PiWeb Delivery & Pickup Date Time for WooCommerce v3.0.62
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-order.php
pi-woocommerce-order-date-time-and-type / public Last commit date
css 3 weeks ago js 3 weeks ago class-css.php 3 weeks ago class-date.php 3 weeks ago class-delivery-type.php 3 weeks ago class-display-field.php 3 weeks ago class-extra-message.php 3 weeks ago class-js.php 3 weeks ago class-main.php 3 weeks ago class-myaccount.php 3 weeks ago class-order.php 3 weeks ago class-pickup-location.php 3 weeks ago class-shipping-method.php 3 weeks ago class-time-range.php 3 weeks ago class-time-slot.php 3 weeks ago class-time.php 3 weeks ago class-validate.php 3 weeks ago class-woo-app.php 3 weeks ago
class-order.php
346 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pi_dtt_order{
6
7 public $email_position;
8 public static $extra_type_support_pickup_location;
9
10 function __construct(){
11
12 $this->email_position = pisol_dtt_get_setting('pi_dtt_detail_position_in_email', 'woocommerce_email_order_meta');
13 /* Update order meta data */
14 add_filter( 'woocommerce_checkout_posted_data', array($this, 'postedData') );
15 /* Update order meta data */
16 add_action( 'woocommerce_checkout_update_order_meta', array(__CLASS__,'storeDetailInOrder'), 10, 2 );
17
18 // Displays order meta on order detail page on front end
19 add_action( 'woocommerce_order_details_after_order_table_items', array($this,'orderSuccessPage'), 10, 1 );
20
21 // Admin order page
22 add_action( 'woocommerce_admin_order_data_after_shipping_address', array($this,'adminOrderSuccessPage'), 10, 1 );
23
24 if($this->email_position == 'woocommerce_email_order_meta'){
25 add_filter( 'woocommerce_email_order_meta_fields', array($this,"orderMetaFieldForEmail"), 10, 3 );
26 }else{
27 add_action( $this->email_position, array($this,"orderSuccessPageEmail"), 10, 4);
28 }
29
30 self::$extra_type_support_pickup_location = apply_filters('pisol_dtt_type_supporting_pickup_location','');
31
32 }
33
34 function postedData($data){
35
36 if(pi_dtt_display_fields::showDateAndTime()):
37
38 if ( ! empty( $_POST['pi_system_delivery_date'] ) ) {
39 $system_date = strtotime($_POST['pi_system_delivery_date']) ? date('Y/m/d',strtotime($_POST['pi_system_delivery_date'])) : "";
40 $data['pi_system_delivery_date'] = sanitize_text_field( $system_date );
41
42 $display_format = pi_dtt_date::translatedDate($system_date);
43 $data['pi_delivery_date'] = sanitize_text_field( $display_format );
44 }
45
46 if ( ! empty( $_POST['pi_delivery_time'] ) ) {
47 $data['pi_delivery_time'] = sanitize_text_field( $_POST['pi_delivery_time'] );
48 }
49 endif;
50
51 $type = pi_dtt_delivery_type::getType();
52 if ( !empty( $type ) && isset($_POST['pi_delivery_type'])) {
53 $data['pi_delivery_type'] = sanitize_text_field($type);
54 }else{
55 $data['pi_delivery_type'] = 'non-deliverable' ;
56 }
57
58 if ( isset($_POST['pickup_location']) && ! empty( $_POST['pickup_location'] ) ) {
59
60 $data['pickup_location'] = sanitize_text_field($_POST['pickup_location']);
61 }
62
63 return $data;
64 }
65
66 static function storeDetailInOrder($order_id, $data){
67 $order = wc_get_order( $order_id );
68
69 if(empty($order)) return;
70
71 if(pi_dtt_display_fields::showDateAndTime()):
72
73 if ( ! empty( $data['pi_system_delivery_date'] ) ) {
74 $system_date = strtotime($data['pi_system_delivery_date']) ? date('Y/m/d',strtotime($data['pi_system_delivery_date'])) : "";
75 $order->update_meta_data( 'pi_system_delivery_date', sanitize_text_field( $system_date ) );
76 $display_format = pi_dtt_date::translatedDate($system_date);
77 $order->update_meta_data( 'pi_delivery_date', sanitize_text_field( $display_format ) );
78 }
79
80 if ( ! empty( $data['pi_delivery_time'] ) ) {
81 $order->update_meta_data( 'pi_delivery_time', pisol_dtt_time::formatTimeForStorage(sanitize_text_field( $data['pi_delivery_time'] )) );
82 }
83 endif;
84
85 $type = pi_dtt_delivery_type::getType();
86 if ( !empty( $type ) && isset($data['pi_delivery_type'])) {
87 $order->update_meta_data( 'pi_delivery_type', sanitize_text_field($type) );
88 }else{
89 $order->update_meta_data( 'pi_delivery_type', 'non-deliverable' );
90 }
91
92 $valid_locations = ['pi_pickup_address_1', 'pi_pickup_address_2'];
93
94 if ( isset($data['pickup_location']) && ! empty( $data['pickup_location'] ) && in_array($data['pickup_location'], $valid_locations) && ($data['pi_delivery_type'] == 'pickup' || $_POST['pi_delivery_type'] == self::$extra_type_support_pickup_location)) {
95 $pickup_address = get_option(sanitize_key($data['pickup_location']), "");
96
97 $order->update_meta_data( 'pickup_location', sanitize_text_field($pickup_address) );
98 }
99
100 $order->save();
101 }
102
103 function orderSuccessPage($order){
104
105
106 $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
107
108 $type = $order->get_meta('pi_delivery_type', true );
109 $old_date = $order->get_meta( 'pi_delivery_date', true );
110 $date = $order->get_meta( 'pi_system_delivery_date', true );
111 $time = $order->get_meta( 'pi_delivery_time', true );
112 $location = $order->get_meta( 'pickup_location', true );
113
114 $dateLabel = __('Date','pisol-dtt');
115 $timeLabel = __('Time','pisol-dtt');
116
117 $delivery_type = '';
118
119 if($type == 'delivery'){
120 $delivery_type = pisol_dtt_get_setting('pi_delivery_label', __('Delivery','pisol-dtt'));
121 }elseif($type == 'pickup'){
122 $delivery_type = pisol_dtt_get_setting('pi_pickup_label', __('Pickup','pisol-dtt'));
123 }elseif($type == 'non-deliverable'){
124 $delivery_type = '';
125 }
126
127
128 $delivery_type = apply_filters('pisol_dtt_delivery_type_label_value',$delivery_type, $type, $order);
129
130 $delivery_type = apply_filters('pisol_dtt_delivery_type_filter_by_order',$delivery_type, $type, $order);
131
132 do_action('pisol_dtt_before_delivery_details', $order);
133
134 if(!empty($type) && $type !== 'non-deliverable'){
135 echo '<p class="pi-order-meta-type"> <strong>'.esc_html__('Delivery type','pisol-dtt').':</strong> ' . esc_html($delivery_type) . '</p>';
136 }
137
138 if(pi_dtt_display_fields::showDateAndTime($type)):
139
140 if(!empty($date)){
141 echo '<p class="pi-order-meta-date"> <strong>'.esc_html($dateLabel).':</strong> ' . esc_html(pi_dtt_date::translatedDate($date)) . '</p>';
142 }elseif(!empty($old_date)){
143 echo '<p class="pi-order-meta-date"> <strong>'.esc_html($dateLabel).':</strong> ' . esc_html($old_date) . '</p>';
144 }
145
146
147 if(!empty($time)){
148 echo '<p class="pi-order-meta-time"> <strong>'.esc_html($timeLabel).':</strong> ' . esc_html(pisol_dtt_time::formatTimeForDisplay($time)) . '</p>';
149 }
150
151
152 endif;
153
154
155
156 $location = $order->get_meta( 'pickup_location', true );
157 if(($type == 'pickup' || $type == self::$extra_type_support_pickup_location) && $location != ''){
158 echo '<p class="pi-order-pickup-location"><strong>'.esc_html( apply_filters('pisol_dtt_pickup_location_label',esc_html__('Pickup location','pisol-dtt'), $type) ).':</strong><br> ' . wp_kses_post($location) . '</p>';
159 }
160
161 do_action('pisol_dtt_after_delivery_details', $order);
162
163 }
164
165 function orderMetaFieldForEmail( $fields, $sent_to_admin, $order ) {
166
167 $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
168
169 $type = $order->get_meta( 'pi_delivery_type', true );
170 $old_date = $order->get_meta( 'pi_delivery_date', true );
171 $date = $order->get_meta( 'pi_system_delivery_date', true );
172 $time = $order->get_meta( 'pi_delivery_time', true );
173 $location = $order->get_meta( 'pickup_location', true );
174
175 $dateLabel = __('Date','pisol-dtt');
176 $timeLabel = __('Time','pisol-dtt');
177
178 if($type == 'delivery'){
179 $delivery_type = pisol_dtt_get_setting('pi_delivery_label', __('Delivery','pisol-dtt'));;
180 }elseif($type == 'pickup'){
181 $delivery_type = pisol_dtt_get_setting('pi_pickup_label', __('Pickup','pisol-dtt'));
182 }elseif($type == 'non-deliverable' || empty($type)){
183 $delivery_type = '';
184 }
185
186
187
188 $delivery_type = apply_filters('pisol_dtt_delivery_type_label_value',$delivery_type, $type, $order);
189
190 $delivery_type = apply_filters('pisol_dtt_delivery_type_filter_by_order',$delivery_type, $type, $order);
191
192 if(!empty($type) && $type !== 'non-deliverable'){
193 $fields['pi_delivery_type'] = array(
194 'label' => __('Delivery type','pisol-dtt'),
195 'value' => esc_html($delivery_type)
196 );
197 }
198
199 if(pi_dtt_display_fields::showDateAndTime($type)):
200
201 if(!empty($date)){
202 $fields['pi_system_delivery_date'] = array(
203 'label' => esc_html($dateLabel),
204 'value' => esc_html(pi_dtt_date::translatedDate($date))
205 );
206 }
207
208
209 if(!empty($time)){
210 $fields['pi_delivery_time'] = array(
211 'label' => esc_html($timeLabel),
212 'value' => esc_html(pisol_dtt_time::formatTimeForDisplay($time))
213 );
214 }
215
216
217 endif;
218
219 $location = $order->get_meta( 'pickup_location', true );
220 if(($type == 'pickup' || $type == self::$extra_type_support_pickup_location) && $location != ''){
221
222 $pickup_location_label = apply_filters('pisol_dtt_pickup_location_label',__('Pickup location','pisol-dtt'), $type);
223
224 $fields['pickup_location'] = array(
225 'label' => $pickup_location_label,
226 'value' => $location
227 );
228 }
229
230 return $fields;
231 }
232
233 function orderSuccessPageEmail($order, $sent_to_admin, $plain_text, $email){
234
235
236 $order_id = version_compare( WC_VERSION, '3.0.0', '<' ) ? $order->id : $order->get_id();
237
238 $type = $order->get_meta( 'pi_delivery_type', true );
239 $old_date = $order->get_meta( 'pi_delivery_date', true );
240 $date = $order->get_meta( 'pi_system_delivery_date', true );
241 $time = $order->get_meta( 'pi_delivery_time', true );
242 $location = $order->get_meta( 'pickup_location', true );
243
244 $dateLabel = __('Date','pisol-dtt');
245 $timeLabel = __('Time','pisol-dtt');
246
247 if($type == 'delivery'){
248 $delivery_type = pisol_dtt_get_setting('pi_delivery_label', __('Delivery','pisol-dtt'));;
249 }elseif($type == 'pickup'){
250 $delivery_type = pisol_dtt_get_setting('pi_pickup_label', __('Pickup','pisol-dtt'));
251 }elseif($type == 'non-deliverable'){
252 $delivery_type = '';
253 }
254
255
256
257 $delivery_type = apply_filters('pisol_dtt_delivery_type_label_value',$delivery_type, $type, $order);
258
259 $delivery_type = apply_filters('pisol_dtt_delivery_type_filter_by_order',$delivery_type, $type, $order);
260
261 do_action('pisol_dtt_before_delivery_details', $order, $plain_text);
262
263 if($plain_text){
264 if(!empty($type) && $type !== 'non-deliverable'){
265 echo esc_html__('Delivery type','pisol-dtt').': ' . esc_html($delivery_type) . "\n";
266 }
267
268 if(pi_dtt_display_fields::showDateAndTime($type)):
269 if(!empty($date)){
270 echo esc_html($dateLabel).': ' . esc_html(pi_dtt_date::translatedDate($date)) ."\n";
271 }elseif(!empty($old_date)){
272 echo esc_html($dateLabel).': ' . esc_html($old_date)."\n";
273 }
274
275 if(!empty($time)){
276 echo esc_html($timeLabel).': ' . esc_html(pisol_dtt_time::formatTimeForDisplay($time)) ."\n";
277 }
278 endif;
279
280 $location = $order->get_meta( 'pickup_location', true );
281 if(($type == 'pickup' || $type == self::$extra_type_support_pickup_location) && $location != ''){
282 echo esc_html(apply_filters('pisol_dtt_pickup_location_label',__('Pickup location','pisol-dtt'), $type)).': ' . wp_kses_post($location) . "\n";
283 }
284 echo "\n =====================\n\n";
285
286 }else{
287
288 if(!empty($type) && $type !== 'non-deliverable'){
289 echo '<p class="pi-order-meta-type"> <strong>'.esc_html__('Delivery type','pisol-dtt').':</strong> ' . esc_html($delivery_type) . '</p>';
290 }
291
292 if(pi_dtt_display_fields::showDateAndTime($type)):
293
294 if(!empty($date)){
295 echo '<p class="pi-order-meta-date"> <strong>'.esc_html($dateLabel).':</strong> ' . esc_html(pi_dtt_date::translatedDate($date)) . '</p>';
296 }elseif(!empty($old_date)){
297 echo '<p class="pi-order-meta-date"> <strong>'.esc_html($dateLabel).':</strong> ' . esc_html($old_date) . '</p><br>';
298 }
299
300 if(!empty($time)){
301 echo '<p class="pi-order-meta-time"> <strong>'.esc_html($timeLabel).':</strong> ' . esc_html(pisol_dtt_time::formatTimeForDisplay($time)) . '</p>';
302 }
303
304 endif;
305
306
307
308 $location = $order->get_meta( 'pickup_location', true );
309 if(($type == 'pickup' || $type == self::$extra_type_support_pickup_location) && $location != ''){
310 echo '<p><strong>'.esc_html(apply_filters('pisol_dtt_pickup_location_label',__('Pickup location','pisol-dtt'), $type)).':</strong><br> ' . wp_kses_post($location) . '</p>';
311 }
312
313 }
314
315 do_action('pisol_dtt_after_delivery_details', $order, $plain_text);
316
317 }
318
319 function adminOrderSuccessPage($order){
320 ?>
321 <div class="order_data_column">
322 <h3><?php esc_html_e('Delivery details','pisol-dtt'); ?></h3>
323 <?php
324 $this->orderSuccessPage($order);
325 ?>
326 </div>
327 <?php
328 }
329
330 }
331
332 add_action('wp_loaded',function(){
333 /**
334 * This filter allow you to hide all the fields added by this plugin
335 * so you can use this to disable the plugin when you have virtual product in
336 * your cart
337 */
338 /*
339 $pisol_disable_dtt_completely = apply_filters('pisol_disable_dtt_completely',false);
340 if($pisol_disable_dtt_completely){
341 return ;
342 }
343 */
344 new pi_dtt_order();
345 });
346