PluginProbe ʕ •ᴥ•ʔ
PiWeb Delivery & Pickup Date Time for WooCommerce / 3.0.49.43
PiWeb Delivery & Pickup Date Time for WooCommerce v3.0.49.43
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 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-validate.php
125 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(__CLASS__,'validateCheckout'),10,2);
16 }
17
18 static 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 /* translators: Date field label */
36 $errors->add('error-date-missing', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), $dateLabel), ['id' => 'pi_delivery_date']);
37 }
38
39
40 if(!empty($date)){
41 if(!pi_dtt_date::isDateValid($date)){
42 /* translators: Date field label */
43 $errors->add('error-date', sprintf(__( '<strong>%s</strong> date you selected is not available any more, please refresh page to get available dates ','pisol-dtt' ), $dateLabel), ['id' => 'pi_delivery_date']);
44 }
45 }
46 }else{
47
48 if(!pi_dtt_date::isDateValid($date) && !empty($date)){
49 /* translators: Date field label */
50 $errors->add('error-date', sprintf(__( '<strong>%s</strong> date you selected is not available any more, please refresh page to get available dates ','pisol-dtt' ), $dateLabel), ['id' => 'pi_delivery_date']);
51 }
52
53 }
54
55 if(pi_dtt_display_fields::enableTimeField() && pi_dtt_display_fields::isTimeRequired()){
56 if (!isset($data['pi_delivery_time']) || empty($data['pi_delivery_time'])){
57 /* translators: Time field label */
58 $errors->add('error-time-missing', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), $timeLabel), ['id' => 'pi_delivery_time']);
59 }
60
61 if(!empty($data['pi_delivery_time'])){
62 if(!pisol_dtt_time::isTimeValid($date, $time)){
63 /* translators: Time field label */
64 $errors->add('error-time', sprintf(__( '<strong>%s</strong> time you inserted is not available any more, please refresh page to get available time','pisol-dtt' ), $timeLabel), ['id' => 'pi_delivery_time']);
65 }
66 }
67 }else{
68
69 if(!pisol_dtt_time::isTimeValid($date, $time) && !empty($time)){
70 /* translators: Time field label */
71 $errors->add('error-time', sprintf(__( '<strong>%s</strong> time you inserted is not available any more, please refresh page to get available time','pisol-dtt' ), $timeLabel), ['id' => 'pi_delivery_time']);
72 }
73 }
74
75 endif;
76
77
78 if(self::isLocationRequired()){
79
80 if (!isset($data['pickup_location']) || empty($data['pickup_location'])){
81 /* translators: Pickup field label */
82 $errors->add('error-location-missing', sprintf(__( '<strong>%s</strong> is a required field','pisol-dtt' ), __('Pickup Location', 'pisol-dtt')), ['id' => 'pisol-pickup-locations']);
83 }
84
85 }
86 }
87
88 /**
89 * Required:
90 * if location is marked as required field in plugin setting
91 * and there is location created in plugin but user zone is not having any location
92 *
93 * not required:
94 * if user has marked it not required
95 *
96 * if user has marked it required but there is no pickup location created in the system
97 */
98 static function isLocationRequired(){
99 $required = apply_filters('pisol_dtt_setting_filter_pi_location_required', 1);
100
101 $type = pi_dtt_delivery_type::getType();
102
103 if( $type == 'pickup' && !empty($required) && $required == '1' && pi_dtt_pickup_location::isLocationPresentInSystem()){
104 return true;
105 }
106
107 return false;
108 }
109
110
111 }
112
113 add_action('wp_loaded',function(){
114 /**
115 * This filter allow you to hide all the fields added by this plugin
116 * so you can use this to disable the plugin when you have virtual product in
117 * your cart
118 */
119 $pisol_disable_dtt_completely = apply_filters('pisol_disable_dtt_completely',false);
120 if($pisol_disable_dtt_completely){
121 return ;
122 }
123
124 new pi_dtt_validate();
125 });