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