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-js.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-js.php
133 lines
1 <?php
2 if ( ! defined( 'WPINC' ) ) {
3 die;
4 }
5 class pi_dtt_js{
6
7 public $plugin_name;
8
9 function __construct(){
10 $this->plugin_name = 'pi-woocommerce-order-date-time-and-type-pro';
11 add_action( 'wp_enqueue_scripts', array($this,'addJs'),990 );
12 }
13
14 function addJs(){
15 if( is_checkout() ){
16 $this->addJsFile();
17 $this->addLocalizedJs();
18 }
19 }
20
21 function addJsFile(){
22
23 wp_enqueue_script( 'jquery-ui-datepicker' );
24 wp_enqueue_script( 'jquery-blockui' );
25 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/pi-woocommerce-order-date-time-and-type-pro-public.js', array( 'jquery','jquery-ui-datepicker', 'jquery-blockui', 'selectWoo' ),'3.3.2.6');
26
27 if(defined( 'ET_CORE_VERSION' ) && apply_filters('pi_dtt_enable_divi_compatibility_js', true)){
28 wp_enqueue_script( $this->plugin_name.'-divi-compatible', plugin_dir_url( __FILE__ ) . 'js/pi-divi-page-builder.js', array( 'jquery'),'3.3.9.3');
29 }
30
31 wp_enqueue_script( $this->plugin_name.'-save-checkout', plugin_dir_url( __FILE__ ) . 'js/save-checkout-data.js', array( 'jquery'),'3.3.2.6');
32 wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full.min.js', array( 'jquery' ) );
33 wp_enqueue_script( 'selectWoo' );
34 wp_enqueue_style( 'select2', WC()->plugin_url() . '/assets/css/select2.css');
35
36 }
37
38 function addLocalizedJs(){
39
40 $localize_values = self::dateOptions();
41 wp_localize_script( 'pi-woocommerce-order-date-time-and-type-pro', 'pi_date_options', $localize_values);
42
43 }
44
45 static function dateOptions(){
46 $minDate = (int)pisol_dtt_get_setting('pi_order_preparation_days',0);
47 $pre_order_days = empty(pisol_dtt_get_setting('pi_preorder_days', 10)) ? 0 : abs(pisol_dtt_get_setting('pi_preorder_days', 10));
48 $allowed_dates = self::allowedDates();
49
50 $maxDateBasedOnDates = self::longestDateAwayFromToday($allowed_dates);
51 if($maxDateBasedOnDates <= ($pre_order_days+$minDate)){
52 $maxDate = apply_filters('pisol_calendar_max_date',$pre_order_days+$minDate);
53 }elseif($maxDateBasedOnDates > ($pre_order_days+$minDate)){
54 $maxDate = apply_filters('pisol_calendar_max_date',$maxDateBasedOnDates);
55 }
56
57 $minDate = self::minDateBasedOnAvailableDates($minDate, $maxDate, $allowed_dates);
58
59 $disable_ajax_loading_location = pi_dtt_pickup_location::isLocationPresentInSystem() ? false : true;
60
61 $return = array(
62 'ajaxUrl'=>admin_url('admin-ajax.php'),
63 'minDate' => $minDate,
64 'maxDate' => $maxDate,
65 'allowedDates' => $allowed_dates,
66 'allSlotsBooked'=>__('All time slots booked for this date','pisol-dtt'),
67 'selectTimeSlot' => __('Time', 'pisol-dtt'),
68 'todaysDate'=>current_time('Y/m/d'),
69 'datePlaceholder' => __('Date','pisol-dtt'),
70 'autoSelectDate'=>apply_filters('pisol_auto_select_date', '0'), // false, first, last
71 'autoSelectTime'=>apply_filters('pisol_auto_select_time', '0'),
72 'allDatesBooked'=>__('All dates are booked', 'pisol-dtt'),
73 'disableAjaxLocationReload'=>apply_filters('pisol_disable_ajax_location',true),
74 'typeSupportingPickupLocation'=> apply_filters('pisol_dtt_type_supporting_pickup_location','')
75 );
76 return apply_filters('pisol_dtt_settings_filter',$return);
77 }
78
79 static function allowedDates(){
80 $obj = new pi_dtt_date();
81 $dates = $obj->getValidDates();
82 return !empty($dates) ? array_values($dates) : array();
83 }
84
85 static function minDateBasedOnAvailableDates($minDate, $maxDate, $allowed_dates){
86
87 if(empty($allowed_dates) || !is_array($allowed_dates)) return $minDate;
88 $today = current_time('Y/m/d');
89 $today_timestamp = strtotime($today);
90 $shortest_date = "";
91 foreach($allowed_dates as $date){
92 if(empty($shortest_date)){
93 $shortest_date = $date;
94 }
95
96 $date_timestamp = strtotime($date);
97 $shortest_date_timestamp = strtotime($shortest_date);
98 if($date_timestamp < $shortest_date_timestamp){
99 $shortest_date = $date;
100 }
101
102 }
103
104 $date1 = date_create($today);
105 $date2 = date_create($shortest_date);
106 $diff = date_diff($date1,$date2);
107 $minDate = $diff->format('%a');
108 if($minDate < 0 || $minDate > $maxDate) return 0;
109 return $minDate;
110 }
111
112 static function longestDateAwayFromToday($dates){
113 if(!is_array($dates)) array();
114 $today = current_time('Y/m/d');
115 $today_timestamp = strtotime($today);
116 $longest_date = $today;
117 foreach($dates as $date){
118
119 $date_timestamp = strtotime($date);
120 $longest_date_timestamp = strtotime($longest_date);
121 if($date_timestamp > $longest_date_timestamp){
122 $longest_date = $date;
123 }
124
125 }
126 $date1=date_create($today);
127 $date2=date_create($longest_date);
128 $diff = date_diff($date1,$date2);
129 return $diff->format('%a');
130 }
131 }
132
133 new pi_dtt_js();