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-js.php
178 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 | $date_label = get_option('pi_dtt_co_label_date', __('Date','pisol-dtt')); |
| 62 | $time_label = get_option('pi_dtt_co_label_time', __('Time','pisol-dtt')); |
| 63 | |
| 64 | $return = array( |
| 65 | 'ajaxUrl'=>admin_url('admin-ajax.php'), |
| 66 | 'minDate' => $minDate, |
| 67 | 'maxDate' => $maxDate, |
| 68 | 'allowedDates' => $allowed_dates, |
| 69 | 'allSlotsBooked'=>__('All time slots booked for this date','pisol-dtt'), |
| 70 | 'selectTimeSlot' => $time_label, |
| 71 | 'todaysDate'=>current_time('Y/m/d'), |
| 72 | 'datePlaceholder' => $date_label, |
| 73 | 'autoSelectDate'=>apply_filters('pisol_auto_select_date', '0'), // false, first, last |
| 74 | 'autoSelectTime'=>apply_filters('pisol_auto_select_time', '0'), |
| 75 | 'allDatesBooked'=>__('All dates are booked', 'pisol-dtt'), |
| 76 | 'disableAjaxLocationReload'=>apply_filters('pisol_disable_ajax_location',true), |
| 77 | 'typeSupportingPickupLocation'=> apply_filters('pisol_dtt_type_supporting_pickup_location',''), |
| 78 | 'delivery_type_label' => self::get_type_label(), |
| 79 | 'date_label' => $date_label, |
| 80 | 'time_label' => $time_label, |
| 81 | 'dateFormat' => self::date_format_for_jquery(), |
| 82 | ); |
| 83 | return apply_filters('pisol_dtt_settings_filter',$return); |
| 84 | } |
| 85 | |
| 86 | static function date_format_for_jquery(){ |
| 87 | $datepicker_date_format = str_replace( |
| 88 | array( |
| 89 | 'd', |
| 90 | 'j', |
| 91 | 'l', |
| 92 | 'z', // Day. |
| 93 | 'F', |
| 94 | 'M', |
| 95 | 'n', |
| 96 | 'm', // Month. |
| 97 | 'Y', |
| 98 | 'y', // Year. |
| 99 | ), |
| 100 | array( |
| 101 | 'dd', |
| 102 | 'd', |
| 103 | 'DD', |
| 104 | 'o', |
| 105 | 'MM', |
| 106 | 'M', |
| 107 | 'm', |
| 108 | 'mm', |
| 109 | 'yy', |
| 110 | 'y', |
| 111 | ), |
| 112 | get_option( 'date_format','F j, Y' ) |
| 113 | ); |
| 114 | return $datepicker_date_format; |
| 115 | } |
| 116 | |
| 117 | static function get_type_label(){ |
| 118 | $show_delivery_type_label = get_option('pi_show_delivery_type_label', 1); |
| 119 | $delivery_type_label_txt = pisol_dtt_get_setting('pi_dtt_co_label_delivery_type', __('Delivery Type','pisol-dtt')); |
| 120 | $delivery_type_label = !empty($show_delivery_type_label) ? $delivery_type_label_txt : ''; |
| 121 | return $delivery_type_label; |
| 122 | } |
| 123 | |
| 124 | static function allowedDates(){ |
| 125 | $obj = new pi_dtt_date(); |
| 126 | $dates = $obj->getValidDates(); |
| 127 | return !empty($dates) ? array_values($dates) : array(); |
| 128 | } |
| 129 | |
| 130 | static function minDateBasedOnAvailableDates($minDate, $maxDate, $allowed_dates){ |
| 131 | |
| 132 | if(empty($allowed_dates) || !is_array($allowed_dates)) return $minDate; |
| 133 | $today = current_time('Y/m/d'); |
| 134 | $today_timestamp = strtotime($today); |
| 135 | $shortest_date = ""; |
| 136 | foreach($allowed_dates as $date){ |
| 137 | if(empty($shortest_date)){ |
| 138 | $shortest_date = $date; |
| 139 | } |
| 140 | |
| 141 | $date_timestamp = strtotime($date); |
| 142 | $shortest_date_timestamp = strtotime($shortest_date); |
| 143 | if($date_timestamp < $shortest_date_timestamp){ |
| 144 | $shortest_date = $date; |
| 145 | } |
| 146 | |
| 147 | } |
| 148 | |
| 149 | $date1 = date_create($today); |
| 150 | $date2 = date_create($shortest_date); |
| 151 | $diff = date_diff($date1,$date2); |
| 152 | $minDate = $diff->format('%a'); |
| 153 | if($minDate < 0 || $minDate > $maxDate) return 0; |
| 154 | return $minDate; |
| 155 | } |
| 156 | |
| 157 | static function longestDateAwayFromToday($dates){ |
| 158 | if(!is_array($dates)) array(); |
| 159 | $today = current_time('Y/m/d'); |
| 160 | $today_timestamp = strtotime($today); |
| 161 | $longest_date = $today; |
| 162 | foreach($dates as $date){ |
| 163 | |
| 164 | $date_timestamp = strtotime($date); |
| 165 | $longest_date_timestamp = strtotime($longest_date); |
| 166 | if($date_timestamp > $longest_date_timestamp){ |
| 167 | $longest_date = $date; |
| 168 | } |
| 169 | |
| 170 | } |
| 171 | $date1=date_create($today); |
| 172 | $date2=date_create($longest_date); |
| 173 | $diff = date_diff($date1,$date2); |
| 174 | return $diff->format('%a'); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | new pi_dtt_js(); |