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