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-display-field.php
239 lines
| 1 | <?php |
| 2 | if ( ! defined( 'WPINC' ) ) { |
| 3 | die; |
| 4 | } |
| 5 | class pi_dtt_display_fields{ |
| 6 | |
| 7 | public $fields_location; |
| 8 | |
| 9 | function __construct(){ |
| 10 | $this->fields_location = apply_filters('pisol_dtt_field_locations', pisol_dtt_get_setting('pi_date_time_location', 'woocommerce_checkout_before_customer_details')); |
| 11 | |
| 12 | add_action( $this->fields_location, array($this,'addingFields')); |
| 13 | |
| 14 | add_action('wp_ajax_pi_set_delivery_type',array($this, 'setDeliveryType')); |
| 15 | add_action('wp_ajax_nopriv_pi_set_delivery_type',array($this, 'setDeliveryType')); |
| 16 | } |
| 17 | |
| 18 | function addingFields(){ |
| 19 | |
| 20 | if(did_action($this->fields_location) > 1 && apply_filters('pisol_dtt_enable_hook_count', true)) return; |
| 21 | |
| 22 | |
| 23 | $pisol_disable_dtt_completely = apply_filters('pisol_disable_dtt_completely',false); |
| 24 | if($pisol_disable_dtt_completely){ |
| 25 | return ; |
| 26 | } |
| 27 | $delivery_type = pi_dtt_delivery_type::getType(); |
| 28 | do_action('pisol_message_before_date_time'); |
| 29 | echo '<div id="pi_checkout_field" class="pi-js-loading">'; |
| 30 | $this->deliveryTypeField($delivery_type); |
| 31 | $this->dateTimeField(); |
| 32 | $this->pickupLocationFields($delivery_type); |
| 33 | do_action('pisol_dtt_custom_display_field'); |
| 34 | echo '</div>'; |
| 35 | do_action('pisol_message_after_date_time'); |
| 36 | } |
| 37 | |
| 38 | function deliveryTypeField($delivery_type = ""){ |
| 39 | |
| 40 | if(empty($delivery_type)){ |
| 41 | $delivery_type = pi_dtt_delivery_type::getType(); |
| 42 | } |
| 43 | |
| 44 | $aloud_types = pisol_dtt_get_setting('pi_type', "Both"); |
| 45 | |
| 46 | $types = array( |
| 47 | 'delivery' => pisol_dtt_get_setting('pi_delivery_label',__('Delivery','pisol-dtt')), |
| 48 | 'pickup' => pisol_dtt_get_setting('pi_pickup_label',__('Pickup','pisol-dtt')) |
| 49 | ); |
| 50 | |
| 51 | if($aloud_types == 'Delivery'){ |
| 52 | unset($types['pickup']); |
| 53 | }elseif($aloud_types == 'Pickup'){ |
| 54 | unset($types['delivery']); |
| 55 | } |
| 56 | |
| 57 | $this->deliveryTypeFieldHtml($delivery_type, $types); |
| 58 | |
| 59 | } |
| 60 | |
| 61 | function deliveryTypeFieldHtml($selected_delivery_type, $show_types){ |
| 62 | $single_type_class = count($show_types) < 2 ? "pi-single-type" : ''; |
| 63 | $show_delivery_type_label = pisol_dtt_get_setting('pi_show_delivery_type_label', 1); |
| 64 | ?> |
| 65 | <p class="form-row pi_delivery_type validate-required" id="pi_delivery_type_field" data-priority=""><?php if(!empty($show_delivery_type_label)): ?><label for="pi_delivery_type_delivery" class=""><?php echo esc_html__('Delivery Type','pisol-dtt'); ?> <abbr class="required" title="<?php echo esc_attr__( 'required', 'woocommerce' ); ?>">*</abbr></label><?php endif; ?><span class="woocommerce-input-wrapper"><?php if(isset($show_types['delivery'])): ?><input type="radio" class="input-radio " value="delivery" name="pi_delivery_type" id="pi_delivery_type_delivery" <?php checked($selected_delivery_type, 'delivery' ); ?>><label for="pi_delivery_type_delivery" class="radio <?php echo esc_attr($single_type_class); ?>"><?php echo esc_html(pisol_dtt_get_setting('pi_delivery_label','Delivery')); ?></label><?php endif; ?><?php if(isset($show_types['pickup'])): ?><input type="radio" class="input-radio " value="pickup" name="pi_delivery_type" id="pi_delivery_type_pickup" <?php checked($selected_delivery_type, 'pickup' ); ?>><label for="pi_delivery_type_pickup" class="radio <?php echo esc_attr($single_type_class); ?>"><?php echo esc_html(pisol_dtt_get_setting('pi_pickup_label','Pickup')); ?></label> |
| 66 | <?php endif; ?><?php do_action('pisol_extra_delivery_type_checkout', $selected_delivery_type); ?></span></p> |
| 67 | <?php |
| 68 | } |
| 69 | |
| 70 | |
| 71 | function dateTimeField(){ |
| 72 | if(self::showDateAndTime()){ |
| 73 | $this->dateField(); |
| 74 | $this->timeField(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | function dateField(){ |
| 79 | woocommerce_form_field( 'pi_delivery_date', array( |
| 80 | 'type' => 'text', |
| 81 | 'required' => self::isDateRequired(), |
| 82 | 'class' => array('pi_delivery_date'), |
| 83 | 'label' => __('Date','pisol-dtt'), |
| 84 | 'placeholder' => __('Date','pisol-dtt'), |
| 85 | 'custom_attributes' => array('readonly'=>'readonly'), |
| 86 | )); |
| 87 | echo '<p style="display:none;"><input type="hidden" name="pi_system_delivery_date" id="pi_system_delivery_date"></p>'; |
| 88 | } |
| 89 | |
| 90 | function timeField(){ |
| 91 | if(self::enableTimeField()){ |
| 92 | woocommerce_form_field( 'pi_delivery_time', array( |
| 93 | 'type' => 'text', |
| 94 | 'required' => self::isTimeRequired(), |
| 95 | 'class' => array('pi_delivery_time'), |
| 96 | 'label' => __('Time','pisol-dtt'), |
| 97 | 'placeholder' => __('Time','pisol-dtt'), |
| 98 | 'custom_attributes' => array('readonly'=>'readonly', 'disabled'=>'disabled'), |
| 99 | )); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | |
| 104 | function pickupLocationFields($delivery_type = ""){ |
| 105 | if(empty($delivery_type)){ |
| 106 | $delivery_type = pi_dtt_delivery_type::getType(); |
| 107 | } |
| 108 | |
| 109 | if($delivery_type != 'pickup') return; |
| 110 | |
| 111 | $address1 = get_option('pi_pickup_address_1', ""); |
| 112 | $address2 = get_option('pi_pickup_address_2', ""); |
| 113 | |
| 114 | if(empty($address1) && empty($address2)){ |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | echo '<div id="pisol-pickup-locations" style="grid-column: span 2;" class="form-row">'; |
| 119 | echo '<label>'.esc_html__('Select a pickup location','pisol-dtt').'</label>'; |
| 120 | echo '<div style="display:flex; flex-wrap:wrap;">'; |
| 121 | if(!empty($address1)){ |
| 122 | echo '<div class="pisol-pickup-add"><input type="radio" name="pickup_location" class="pisol-location-radio" value="pi_pickup_address_1" id="pi_pickup_address_1" checked="checked"><label class="pisol-location" for="pi_pickup_address_1">'.wp_kses_post($address1).'</label></div>'; |
| 123 | } |
| 124 | if(!empty($address2)){ |
| 125 | echo '<div class="pisol-pickup-add"><input type="radio" name="pickup_location" class="pisol-location-radio" value="pi_pickup_address_2" id="pi_pickup_address_2"><label class="pisol-location" for="pi_pickup_address_2">'.wp_kses_post($address2).'</label></div>'; |
| 126 | } |
| 127 | echo '</div>'; |
| 128 | echo '</div>'; |
| 129 | } |
| 130 | |
| 131 | function setDeliveryType(){ |
| 132 | $type = sanitize_text_field($_GET['type']); |
| 133 | $obj = new pi_dtt_delivery_type(); |
| 134 | $set_type = $obj->setDeliveryType($type); |
| 135 | echo esc_attr($set_type); |
| 136 | die; |
| 137 | } |
| 138 | |
| 139 | static function dateFormat(){ |
| 140 | $format = pisol_dtt_get_setting('date_format','F j, Y'); |
| 141 | return $format; |
| 142 | } |
| 143 | |
| 144 | static function showDateAndTime($type = ""){ |
| 145 | if(empty($type)){ |
| 146 | $type = pi_dtt_delivery_type::getType(); |
| 147 | } |
| 148 | |
| 149 | $show_date_time = pisol_dtt_get_setting('pi_datetime', 'enable-both'); |
| 150 | |
| 151 | switch($show_date_time){ |
| 152 | case '0': |
| 153 | return false; |
| 154 | break; |
| 155 | |
| 156 | case '1': |
| 157 | return true; |
| 158 | break; |
| 159 | |
| 160 | case 'disable-both': |
| 161 | return false; |
| 162 | break; |
| 163 | |
| 164 | case 'enable-both': |
| 165 | return true; |
| 166 | break; |
| 167 | |
| 168 | case 'pickup-only': |
| 169 | if($type == 'pickup'){ |
| 170 | return true; |
| 171 | }else{ |
| 172 | return false; |
| 173 | } |
| 174 | break; |
| 175 | |
| 176 | case 'delivery-only': |
| 177 | if($type == 'delivery'){ |
| 178 | return true; |
| 179 | }else{ |
| 180 | return false; |
| 181 | } |
| 182 | break; |
| 183 | |
| 184 | default: |
| 185 | return true; |
| 186 | |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | static function enableTimeField($type = ""){ |
| 191 | $saved_option = pisol_dtt_get_setting('pi_enable_delivery_time', 'enable-both'); |
| 192 | $return = false; |
| 193 | if(empty($type)){ |
| 194 | $delivery_type = pi_dtt_delivery_type::getType(); |
| 195 | }else{ |
| 196 | $delivery_type = $type; |
| 197 | } |
| 198 | |
| 199 | if( $saved_option == "enable-both"){ |
| 200 | $return = true; |
| 201 | } |
| 202 | |
| 203 | if( $saved_option == "disable-both"){ |
| 204 | $return = false; |
| 205 | } |
| 206 | |
| 207 | if( ($saved_option == 'only-pickup' && $delivery_type == 'pickup')){ |
| 208 | $return = true; |
| 209 | } |
| 210 | |
| 211 | if( ($saved_option == 'only-delivery' && $delivery_type == 'delivery')){ |
| 212 | $return = true; |
| 213 | } |
| 214 | return $return; |
| 215 | } |
| 216 | |
| 217 | static function isTimeRequired($type = ""){ |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | static function isLocationRequired(){ |
| 222 | $required = pisol_dtt_get_setting('pi_location_required','0'); |
| 223 | $extra_type_support_pickup_location = apply_filters('pisol_dtt_type_supporting_pickup_location',''); |
| 224 | $type = pi_dtt_delivery_type::getType(); |
| 225 | $obj = new pi_dtt_pickup_location(); |
| 226 | if( ($type == 'pickup' || $type == $extra_type_support_pickup_location) && !empty($required) && $required == '1' && $obj->isLocationPresent()){ |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | static function isDateRequired($type = ""){ |
| 234 | |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | } |