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-validate.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-validate.php
118 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pi_dtt_validate{
6 function __construct(){
7 /* validating field */
8 /** old validation method */
9 //add_action('woocommerce_checkout_process', array($this,'validateCheckout'));
10
11 /**
12 * New validation based on this hook
13 * https://github.com/woocommerce/woocommerce/blob/23710744c01ded649d6a94a4eaea8745e543159f/includes/class-wc-checkout.php#L878
14 */
15 add_action('woocommerce_after_checkout_validation', array($this,'validateCheckout'),10,2);
16 }
17
18 function validateCheckout($data, $errors){
19
20 $pisol_disable_dtt_completely = apply_filters('pisol_disable_dtt_completely',false);
21 if($pisol_disable_dtt_completely){
22 return ;
23 }
24
25
26 $dateLabel = __('Date','pisol-dtt');
27 $timeLabel = __('Time','pisol-dtt');
28
29 $date = isset($data['pi_system_delivery_date']) ? sanitize_text_field($data['pi_system_delivery_date']) : "";
30 $time = isset($data['pi_delivery_time']) ? sanitize_text_field($data['pi_delivery_time']) : "";
31
32 if(pi_dtt_display_fields::showDateAndTime()):
33 if(pi_dtt_display_fields::isDateRequired()){
34 if (!isset($data['pi_system_delivery_date']) || empty( $data['pi_system_delivery_date'])){
35 $errors->add('error', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), $dateLabel));
36 }
37
38
39 if(!empty($date)){
40 if(!pi_dtt_date::isDateValid($date)){
41 $errors->add('error', sprintf(__( '<strong>%s</strong> date you selected is not available any more, please refresh page to get available dates ','pisol-dtt' ), $dateLabel));
42 }
43 }
44 }else{
45
46 if(!pi_dtt_date::isDateValid($date) && !empty($date)){
47 $errors->add('error', sprintf(__( '<strong>%s</strong> date you selected is not available any more, please refresh page to get available dates ','pisol-dtt' ), $dateLabel));
48 }
49
50 }
51
52 if(pi_dtt_display_fields::enableTimeField() && pi_dtt_display_fields::isTimeRequired()){
53 if (!isset($data['pi_delivery_time']) || empty($data['pi_delivery_time'])){
54 $errors->add('error', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), $timeLabel));
55 }
56
57 if(!empty($data['pi_delivery_time'])){
58 if(!pisol_dtt_time::isTimeValid($date, $time)){
59 $errors->add('error', sprintf(__( '<strong>%s</strong> time you inserted is not available any more, please refresh page to get available time','pisol-dtt' ), $timeLabel));
60 }
61 }
62 }else{
63
64 if(!pisol_dtt_time::isTimeValid($date, $time) && !empty($time)){
65 $errors->add('error', sprintf(__( '<strong>%s</strong> time you inserted is not available any more, please refresh page to get available time','pisol-dtt' ), $timeLabel));
66 }
67 }
68
69 endif;
70
71
72 if(self::isLocationRequired()){
73
74 if (!isset($data['pickup_location']) || empty($data['pickup_location'])){
75 $errors->add('error', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), __('Pickup Location', 'pisol-dtt')));
76 }
77
78 }
79 }
80
81 /**
82 * Required:
83 * if location is marked as required field in plugin setting
84 * and there is location created in plugin but user zone is not having any location
85 *
86 * not required:
87 * if user has marked it not required
88 *
89 * if user has marked it required but there is no pickup location created in the system
90 */
91 static function isLocationRequired(){
92 $required = 1;
93
94 $type = pi_dtt_delivery_type::getType();
95
96 if( $type == 'pickup' && !empty($required) && $required == '1' && pi_dtt_pickup_location::isLocationPresentInSystem()){
97 return true;
98 }
99
100 return false;
101 }
102
103
104 }
105
106 add_action('wp_loaded',function(){
107 /**
108 * This filter allow you to hide all the fields added by this plugin
109 * so you can use this to disable the plugin when you have virtual product in
110 * your cart
111 */
112 $pisol_disable_dtt_completely = apply_filters('pisol_disable_dtt_completely',false);
113 if($pisol_disable_dtt_completely){
114 return ;
115 }
116
117 new pi_dtt_validate();
118 });