| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\Renderer; |
| 4 |
|
| 5 |
use FluentCart\App\Services\Localization\LocalizationManager; |
| 6 |
use FluentCart\Framework\Support\Arr; |
| 7 |
|
| 8 |
class AddressSelectRenderer |
| 9 |
{ |
| 10 |
public string $address_type = 'billing'; |
| 11 |
public string $title = ''; |
| 12 |
public array $addresses = []; |
| 13 |
public array $countries = []; |
| 14 |
public array $primary_address = []; |
| 15 |
public string $value = ''; |
| 16 |
public array $requirements_fields = []; |
| 17 |
|
| 18 |
public function __construct($addresses, $primary_address, $requirements_fields, $address_type) |
| 19 |
{ |
| 20 |
$this->title = $address_type === 'billing' ? __('Billing Address', 'fluent-cart') : __('Shipping Address', 'fluent-cart'); |
| 21 |
$this->addresses = $addresses; |
| 22 |
$this->primary_address = $primary_address; |
| 23 |
$this->requirements_fields = $requirements_fields; |
| 24 |
$this->address_type = $address_type; |
| 25 |
$this->countries = LocalizationManager::getInstance()->countries(); |
| 26 |
} |
| 27 |
|
| 28 |
public function render() |
| 29 |
{ |
| 30 |
?> |
| 31 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 32 |
id="<?php echo esc_attr($this->address_type); ?>_address_wrapper" role="group" |
| 33 |
aria-labelledby="<?php echo esc_attr($this->address_type); ?>_address_label"> |
| 34 |
<div data-fluent-cart-checkout-page-form-address-select-wrapper="" class="fct_address_wrapper"> |
| 35 |
<?php $this->renderAddressInfo(); ?> |
| 36 |
<?php $this->renderAddressModal(); ?> |
| 37 |
</div> |
| 38 |
</div> |
| 39 |
<?php |
| 40 |
} |
| 41 |
|
| 42 |
public function renderAddressInfo() |
| 43 |
{ |
| 44 |
$attributes = [ |
| 45 |
'data-fluent-cart-checkout-page-form-address-input' => '', |
| 46 |
'name' => $this->address_type . '_address_id', |
| 47 |
'data-required' => 'no', |
| 48 |
'data-type' => 'input', |
| 49 |
'id' => $this->address_type . '_address_id', |
| 50 |
'checked' => 'no', |
| 51 |
'value' => $this->primary_address['id'], |
| 52 |
'data-country' => $this->primary_address['country'], |
| 53 |
'data-state' => $this->primary_address['state'], |
| 54 |
'type' => 'hidden' |
| 55 |
]; |
| 56 |
?> |
| 57 |
<label id="<?php echo esc_attr($this->address_type); ?>_address_label" class="sr-only"> |
| 58 |
<?php echo esc_html(ucfirst($this->address_type)); ?> Address |
| 59 |
</label> |
| 60 |
|
| 61 |
<input <?php RenderHelper::renderAtts($attributes); ?> aria-labelledby="<?php echo esc_attr($this->address_type); ?>_address_label |
| 62 |
<?php echo esc_attr($this->address_type); ?>_address_info"> |
| 63 |
<div class="fct_address_info" data-fluent-cart-checkout-page-form-address-info-wrapper |
| 64 |
id="<?php echo esc_attr($this->address_type); ?>_address_info"> |
| 65 |
<div class="fct_checkout_address_label"> |
| 66 |
<span><?php echo esc_html($this->primary_address['name']); ?></span> |
| 67 |
<span><?php echo esc_html(Arr::get($this->primary_address, 'phone')); ?></span> |
| 68 |
</div> |
| 69 |
<p> |
| 70 |
<?php if (!empty(Arr::get($this->primary_address, 'label'))): ?> |
| 71 |
<span> <?php echo esc_html(Arr::get($this->primary_address, 'label')); ?></span> |
| 72 |
<?php endif; ?> |
| 73 |
<?php echo esc_html($this->primary_address['formatted_address']['full_address']); ?> |
| 74 |
</p> |
| 75 |
</div> |
| 76 |
<?php |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
public function renderAddressModal() |
| 82 |
{ |
| 83 |
?> |
| 84 |
<div class="fct_address_modal_wrapper" data-fluent-cart-checkout-page-form-address-modal-wrapper=""> |
| 85 |
<button class="fct_address_modal_open_btn" type="button" |
| 86 |
data-fluent-cart-checkout-page-form-address-modal-open-button |
| 87 |
aria-label="<?php echo esc_attr__('Change Address', 'fluent-cart'); ?>"> |
| 88 |
<svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 16 16" |
| 89 |
fill="none"> |
| 90 |
<g clip-path="url(#clip0_3536_3207)"> |
| 91 |
<path |
| 92 |
d="M9.38263 2.59046C9.87942 2.05222 10.1278 1.78309 10.3918 1.62611C11.0287 1.24734 11.8129 1.23556 12.4604 1.59504C12.7288 1.74403 12.9848 2.00558 13.4969 2.52867C14.0089 3.05176 14.265 3.31331 14.4108 3.58745C14.7627 4.24891 14.7512 5.05002 14.3804 5.70063C14.2267 5.97027 13.9633 6.22401 13.4364 6.7315L7.16725 12.7697C6.16875 13.7314 5.6695 14.2123 5.04554 14.456C4.42158 14.6997 3.73563 14.6818 2.36374 14.6459L2.17708 14.641C1.75943 14.6301 1.55061 14.6246 1.42922 14.4869C1.30783 14.3491 1.3244 14.1364 1.35755 13.7109L1.37555 13.4799C1.46883 12.2825 1.51548 11.6838 1.7493 11.1456C1.98312 10.6075 2.38645 10.1705 3.19311 9.2965L9.38263 2.59046Z" |
| 93 |
stroke="currentColor" stroke-linejoin="round"></path> |
| 94 |
<path d="M8.66699 2.66699L13.3337 7.33366" stroke="currentColor" stroke-linejoin="round"></path> |
| 95 |
<path d="M9.3335 14.667L14.6668 14.667" stroke="currentColor" stroke-linecap="round" |
| 96 |
stroke-linejoin="round"></path> |
| 97 |
</g> |
| 98 |
<defs> |
| 99 |
<clipPath id="clip0_3536_3207"> |
| 100 |
<rect width="16" height="16" fill="white"></rect> |
| 101 |
</clipPath> |
| 102 |
</defs> |
| 103 |
</svg> |
| 104 |
<?php echo esc_html__('Change', 'fluent-cart'); ?> |
| 105 |
</button> |
| 106 |
|
| 107 |
<div data-fluent-cart-checkout-page-form-address-modal-body="" class="fct_address_modal hidden" |
| 108 |
data-fluent-cart-address-type="<?php echo esc_attr($this->address_type); ?>" role="dialog" aria-modal="true" |
| 109 |
aria-labelledby="<?php echo esc_attr($this->address_type); ?>_address_modal_title"> |
| 110 |
|
| 111 |
<div class="fct_address_modal_inner"> |
| 112 |
<div class="fct_address_modal_header"> |
| 113 |
<h4 id="<?php echo esc_attr($this->address_type); ?>_address_modal_title"> |
| 114 |
<?php echo esc_html($this->title); ?> |
| 115 |
</h4> |
| 116 |
</div> |
| 117 |
|
| 118 |
<button class="fct_address_modal_close_btn" type="button" |
| 119 |
data-fluent-cart-checkout-page-form-address-modal-close-button |
| 120 |
aria-label="<?php echo esc_attr__('Close', 'fluent-cart'); ?>"> |
| 121 |
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> |
| 122 |
<path |
| 123 |
d="M6.2253 4.81108C5.83477 4.42056 5.20161 4.42056 4.81108 4.81108C4.42056 5.20161 4.42056 5.83477 4.81108 6.2253L10.5858 12L4.81114 17.7747C4.42062 18.1652 4.42062 18.7984 4.81114 19.1889C5.20167 19.5794 5.83483 19.5794 6.22535 19.1889L12 13.4142L17.7747 19.1889C18.1652 19.5794 18.7984 19.5794 19.1889 19.1889C19.5794 18.7984 19.5794 18.1652 19.1889 17.7747L13.4142 12L19.189 6.2253C19.5795 5.83477 19.5795 5.20161 19.189 4.81108C18.7985 4.42056 18.1653 4.42056 17.7748 4.81108L12 10.5858L6.2253 4.81108Z"> |
| 124 |
</path> |
| 125 |
</svg> |
| 126 |
</button> |
| 127 |
|
| 128 |
<div class="fct_address_modal_body"> |
| 129 |
<?php $this->renderAddressSelector(); ?> |
| 130 |
<?php $this->renderAddAddressForm(); ?> |
| 131 |
</div> |
| 132 |
|
| 133 |
<?php $this->renderAddressModalFooter(); ?> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<?php |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
public function renderAddressModalFooter() |
| 143 |
{ |
| 144 |
?> |
| 145 |
<div class="fct_address_modal_footer"> |
| 146 |
<div class="fct_address_add_btn" data-fluent-cart-checkout-page-form-address-show-add-new-modal-button |
| 147 |
aria-label="<?php echo esc_attr__('Add new address', 'fluent-cart'); ?>"> |
| 148 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 149 |
<path d="M7 1.6665V12.3332" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" |
| 150 |
stroke-linejoin="round"></path> |
| 151 |
<path d="M1.6665 7H12.3332" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" |
| 152 |
stroke-linejoin="round"></path> |
| 153 |
</svg> |
| 154 |
<?php echo esc_html__('Add Address', 'fluent-cart'); ?> |
| 155 |
</div> |
| 156 |
|
| 157 |
<button class="fct_address_apply_btn" type="button" |
| 158 |
data-fluent-cart-checkout-page-form-address-modal-apply-button="" data-address-id="1" |
| 159 |
aria-label="<?php echo esc_attr__('Apply selected address', 'fluent-cart'); ?>"> |
| 160 |
<?php echo esc_html__('Apply', 'fluent-cart'); ?> |
| 161 |
</button> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
} |
| 165 |
|
| 166 |
public function renderAddressSelector() |
| 167 |
{ |
| 168 |
?> |
| 169 |
<div data-fluent-cart-checkout-page-form-address-modal-address-selector-button-wrapper="" |
| 170 |
class="fct_address_selector_wrapper"> |
| 171 |
<?php if (!empty($this->addresses)): |
| 172 |
foreach ($this->addresses as $address): ?> |
| 173 |
<div class="fct_address_selector" data-id="<?php echo esc_attr($address['id']); ?>" |
| 174 |
data-fluent-cart-checkout-page-form-address-modal-address-selector-button="" |
| 175 |
data-country="<?php echo esc_attr($address['country']); ?>" |
| 176 |
data-state="<?php echo esc_attr($address['state']); ?>" role="button" tabindex="0" aria-pressed="false"> |
| 177 |
|
| 178 |
<svg class="fct_address_selector_icon" xmlns="http://www.w3.org/2000/svg" width="28" height="28" |
| 179 |
viewBox="0 0 28 28" fill="none"> |
| 180 |
<path d="M0 6C0 2.68629 2.68629 0 6 0H28L14 14L0 28V6Z" fill="currentColor"></path> |
| 181 |
<path d="M5.2915 9.4165L6.89567 11.0207L11.7082 5.979" stroke="white" stroke-width="1.5" |
| 182 |
stroke-linecap="round" stroke-linejoin="round"></path> |
| 183 |
</svg> |
| 184 |
|
| 185 |
<?php if (!empty(Arr::get($address, 'formatted_address.name')) || !empty(Arr::get($address, 'phone'))): ?> |
| 186 |
<div class="fct_address_selector_label"> |
| 187 |
<?php if (!empty(Arr::get($address, 'formatted_address.name'))): ?> |
| 188 |
<span><?php echo esc_html(Arr::get($address, 'formatted_address.name')); ?> </span> |
| 189 |
<?php endif; ?> |
| 190 |
<?php if (!empty(Arr::get($address, 'phone'))): ?> |
| 191 |
<span> <?php echo esc_html(Arr::get($address, 'phone')); ?></span> |
| 192 |
<?php endif; ?> |
| 193 |
</div> |
| 194 |
<?php endif; ?> |
| 195 |
|
| 196 |
<p class="fct_address_selector_info"> |
| 197 |
<?php if (!empty(Arr::get($address, 'label'))): ?> |
| 198 |
<span> <?php echo esc_html(Arr::get($address, 'label')); ?></span> |
| 199 |
<?php endif; ?> |
| 200 |
|
| 201 |
<?php echo esc_html(Arr::get($address, 'formatted_address.full_address')); ?> |
| 202 |
</p> |
| 203 |
</div> |
| 204 |
<?php endforeach; ?> |
| 205 |
<?php else: ?> |
| 206 |
<div class="fct_address_selector"> |
| 207 |
<p class="fct_address_selector_info"> |
| 208 |
<?php echo esc_html__('No address found', 'fluent-cart'); ?> |
| 209 |
</p> |
| 210 |
</div> |
| 211 |
<?php endif; ?> |
| 212 |
</div> |
| 213 |
<?php |
| 214 |
} |
| 215 |
|
| 216 |
public function renderAddAddressForm() |
| 217 |
{ |
| 218 |
?> |
| 219 |
<div class="fct_add_new_address_form" data-fluent-cart-checkout-page-form-address-show-add-new-modal-form-wrapper=""> |
| 220 |
<div id="<?php echo esc_attr($this->address_type); ?>_address_section_section" |
| 221 |
data-fluent-cart-checkout-page-form-section="" class="fct_checkout_form_section additional-address-field"> |
| 222 |
<div class="fct_form_section_header"> |
| 223 |
<h4 class="fct_form_section_header_label"><?php echo esc_html__('Address', 'fluent-cart'); ?></h4> |
| 224 |
</div> |
| 225 |
|
| 226 |
<div class="fct_form_section_body"> |
| 227 |
<div class="fct_checkout_input_group"> |
| 228 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 229 |
id="<?php echo esc_attr($this->address_type); ?>_label_wrapper"> |
| 230 |
<label for="<?php echo esc_attr($this->address_type); ?>_label" class="sr-only"> |
| 231 |
<?php echo esc_html__('Address Label', 'fluent-cart'); ?> |
| 232 |
</label> |
| 233 |
|
| 234 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_label" autocomplete="label" |
| 235 |
placeholder="<?php echo esc_html__('e.g Home, Office', 'fluent-cart'); ?>" data-required="yes" |
| 236 |
data-type="input" id="<?php echo esc_attr($this->address_type); ?>_label" maxlength="15" |
| 237 |
aria-describedby="<?php echo esc_attr($this->address_type); ?>_label_description"> |
| 238 |
|
| 239 |
<span id="<?php echo esc_attr($this->address_type); ?>_label_description" class="sr-only"> |
| 240 |
<?php echo esc_html__('Maximum 15 characters', 'fluent-cart'); ?> |
| 241 |
</span> |
| 242 |
|
| 243 |
</div> |
| 244 |
|
| 245 |
|
| 246 |
<?php $this->renderNameFields(); ?> |
| 247 |
|
| 248 |
<?php $this->renderBusinessDetailsFields(); ?> |
| 249 |
|
| 250 |
<?php if (!empty(Arr::get($this->requirements_fields, 'phone'))): ?> |
| 251 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 252 |
id="<?php echo esc_attr($this->address_type); ?>_phone_wrapper"> |
| 253 |
<label for="<?php echo esc_attr($this->address_type); ?>_phone" class="sr-only"> |
| 254 |
<?php echo esc_html__('Phone Number', 'fluent-cart'); ?> |
| 255 |
</label> |
| 256 |
|
| 257 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_phone" |
| 258 |
placeholder="<?php echo esc_html__('Phone number', 'fluent-cart'); ?>" data-required="no" |
| 259 |
data-type="input" id="<?php echo esc_attr($this->address_type); ?>_phone"> |
| 260 |
</div> |
| 261 |
<?php endif; ?> |
| 262 |
|
| 263 |
<?php if (!empty(Arr::get($this->requirements_fields, 'country'))): ?> |
| 264 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 265 |
id="<?php echo esc_attr($this->address_type); ?>_country_wrapper"> |
| 266 |
<label for="<?php echo esc_attr($this->address_type); ?>_country" class="sr-only"> |
| 267 |
<?php echo esc_html__('Country / Region', 'fluent-cart'); ?> |
| 268 |
</label> |
| 269 |
|
| 270 |
<select type="text" name="<?php echo esc_attr($this->address_type); ?>_country" |
| 271 |
autocomplete="country" |
| 272 |
data-required="<?php echo Arr::get($this->requirements_fields, 'country') === 'required' ? 'yes' : ''; ?>" |
| 273 |
data-type="input" id="<?php echo esc_attr($this->address_type); ?>_country" |
| 274 |
class="hidden-select"> |
| 275 |
<option value=""> |
| 276 |
<?php echo esc_html__('Select a Country', 'fluent-cart'); ?> |
| 277 |
</option> |
| 278 |
<?php foreach ($this->countries as $countryCode => $country): ?> |
| 279 |
<option value="<?php echo esc_attr($countryCode); ?>"> |
| 280 |
<?php echo esc_html($country); ?> |
| 281 |
</option> |
| 282 |
<?php endforeach; ?> |
| 283 |
</select> |
| 284 |
</div> |
| 285 |
<?php endif; ?> |
| 286 |
|
| 287 |
<?php if (!empty(Arr::get($this->requirements_fields, 'address_1'))): ?> |
| 288 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 289 |
id="<?php echo esc_attr($this->address_type); ?>_address_1_wrapper"> |
| 290 |
<label for="<?php echo esc_attr($this->address_type); ?>_address_1" class="sr-only"> |
| 291 |
<?php echo esc_html__('Street Address', 'fluent-cart'); ?> |
| 292 |
<?php echo Arr::get($this->requirements_fields, 'address_1') === 'required' ? esc_html__(' (required)', 'fluent-cart') : ''; ?> |
| 293 |
</label> |
| 294 |
<?php |
| 295 |
$placeholder_text = esc_html__('Street Address', 'fluent-cart'); |
| 296 |
if (Arr::get($this->requirements_fields, 'address_1') === 'required') { |
| 297 |
$placeholder_text .= ' ' . esc_html__('*', 'fluent-cart'); |
| 298 |
} |
| 299 |
?> |
| 300 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_address_1" |
| 301 |
autocomplete="address-line1" placeholder="<?php echo esc_attr($placeholder_text); ?>" |
| 302 |
data-required="yes" data-type="input" aria-required="true" |
| 303 |
id="<?php echo esc_attr($this->address_type); ?>_address_1"> |
| 304 |
</div> |
| 305 |
<?php endif; ?> |
| 306 |
|
| 307 |
<?php if (!empty(Arr::get($this->requirements_fields, 'address_2'))): ?> |
| 308 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 309 |
id="<?php echo esc_attr($this->address_type); ?>_address_2_wrapper"> |
| 310 |
<label for="<?php echo esc_attr($this->address_type); ?>_address_2" class="sr-only"> |
| 311 |
<?php echo esc_html__('Apartment, suite, unit, etc.', 'fluent-cart'); ?> |
| 312 |
</label> |
| 313 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_address_2" |
| 314 |
autocomplete="address-line2" |
| 315 |
placeholder="<?php echo esc_html__('Apt, suite, unit', 'fluent-cart'); ?>" data-required="no" |
| 316 |
data-type="input" id="<?php echo esc_attr($this->address_type); ?>_address_2"> |
| 317 |
</div> |
| 318 |
<?php endif; ?> |
| 319 |
|
| 320 |
<?php if (!empty(Arr::get($this->requirements_fields, 'state'))): ?> |
| 321 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 322 |
id="<?php echo esc_attr($this->address_type); ?>_state_wrapper" style="display: block;"> |
| 323 |
<label for="<?php echo esc_attr($this->address_type); ?>_state" class="sr-only"> |
| 324 |
<?php echo esc_html__('State / Province', 'fluent-cart'); ?> |
| 325 |
</label> |
| 326 |
|
| 327 |
<select type="select" name="<?php echo esc_attr($this->address_type); ?>_state" |
| 328 |
autocomplete="address-level1" data-required="yes" data-type="input" |
| 329 |
id="<?php echo esc_attr($this->address_type); ?>_state" checked="no" class="hidden-select"> |
| 330 |
<option value=""><?php echo esc_html__('Select a State', 'fluent-cart'); ?></option> |
| 331 |
</select> |
| 332 |
</div> |
| 333 |
<?php endif; ?> |
| 334 |
|
| 335 |
|
| 336 |
<div id="<?php echo esc_attr($this->address_type); ?>_city_zip_section" |
| 337 |
data-fluent-cart-checkout-page-form-section="" |
| 338 |
class="fct_checkout_form_section <?php echo empty(Arr::get($this->requirements_fields, 'postcode')) ? 'full-column' : '' ?>"> |
| 339 |
|
| 340 |
<div class="fct_form_section_body"> |
| 341 |
<div class="fct_checkout_input_group"> |
| 342 |
<?php if (!empty(Arr::get($this->requirements_fields, 'city'))): ?> |
| 343 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 344 |
id="<?php echo esc_attr($this->address_type); ?>_city_wrapper"> |
| 345 |
<label for="<?php echo esc_attr($this->address_type); ?>_city" class="sr-only"> |
| 346 |
<?php echo esc_html__('City / Town', 'fluent-cart'); ?> |
| 347 |
</label> |
| 348 |
|
| 349 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_city" |
| 350 |
autocomplete="address-level2" |
| 351 |
placeholder="<?php echo esc_html__('City / Town', 'fluent-cart'); ?>" |
| 352 |
data-required="yes" data-type="input" |
| 353 |
id="<?php echo esc_attr($this->address_type); ?>_city" aria-required="true"> |
| 354 |
</div> |
| 355 |
<?php endif; ?> |
| 356 |
<?php if (!empty(Arr::get($this->requirements_fields, 'postcode'))): ?> |
| 357 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 358 |
id="<?php echo esc_attr($this->address_type); ?>_postcode_wrapper"> |
| 359 |
<label for="<?php echo esc_attr($this->address_type); ?>_postcode" class="sr-only"> |
| 360 |
<?php echo esc_html__('Postcode / ZIP', 'fluent-cart'); ?> |
| 361 |
</label> |
| 362 |
|
| 363 |
<input type="text" name="<?php echo esc_attr($this->address_type); ?>_postcode" |
| 364 |
autocomplete="postal-code" |
| 365 |
placeholder="<?php echo esc_attr__('Postcode / ZIP', 'fluent-cart'); ?>" |
| 366 |
data-required="yes" data-type="input" |
| 367 |
id="<?php echo esc_attr($this->address_type); ?>_postcode" aria-required="true"> |
| 368 |
</div> |
| 369 |
<?php endif; ?> |
| 370 |
</div> |
| 371 |
</div> |
| 372 |
</div> |
| 373 |
|
| 374 |
</div> |
| 375 |
</div> |
| 376 |
<div class="fct_form_error fct_error_<?php echo esc_attr($this->address_type . '_address_section_section'); ?>"></div> |
| 377 |
</div> |
| 378 |
<div class="fct_add_new_address_form_footer"> |
| 379 |
|
| 380 |
<button class="fct_address_cancel_btn" type="button" |
| 381 |
data-fluent-cart-checkout-page-form-address-show-add-new-modal-cancel-button |
| 382 |
aria-label="<?php echo esc_attr__('Cancel', 'fluent-cart'); ?>"> |
| 383 |
<?php echo esc_html__('Cancel', 'fluent-cart'); ?> |
| 384 |
</button> |
| 385 |
|
| 386 |
<button class="fct_address_submit_btn" type="submit" |
| 387 |
data-fluent-cart-checkout-page-form-address-show-add-new-modal-submit-button |
| 388 |
aria-label="<?php echo esc_attr__('Submit', 'fluent-cart'); ?>"> |
| 389 |
<?php echo esc_html__('Submit', 'fluent-cart'); ?> |
| 390 |
</button> |
| 391 |
</div> |
| 392 |
</div> |
| 393 |
<?php |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
public function renderNameFields() { |
| 398 |
|
| 399 |
$type = esc_attr($this->address_type); |
| 400 |
|
| 401 |
if (CheckoutFieldsSchema::isFullNameRequired()) : ?> |
| 402 |
<div class="fct_input_wrapper" id="<?php echo $type; ?>_name_wrapper"> |
| 403 |
<label for="<?php echo $type; ?>_full_name" class="sr-only"> |
| 404 |
<?php echo esc_html__('Full Name', 'fluent-cart'); ?> |
| 405 |
</label> |
| 406 |
|
| 407 |
<input |
| 408 |
type="text" |
| 409 |
name="<?php echo $type; ?>_full_name" |
| 410 |
id="<?php echo $type; ?>_full_name" |
| 411 |
autocomplete="name" |
| 412 |
placeholder="<?php echo esc_attr__('Full Name', 'fluent-cart'); ?>" |
| 413 |
data-required="yes" |
| 414 |
data-type="input" |
| 415 |
> |
| 416 |
</div> |
| 417 |
|
| 418 |
<?php else : ?> |
| 419 |
|
| 420 |
<div class="fct_input_wrapper" id="<?php echo $type; ?>_first_name_wrapper"> |
| 421 |
<label for="<?php echo $type; ?>_first_name" class="sr-only"> |
| 422 |
<?php echo esc_html__('First Name', 'fluent-cart'); ?> |
| 423 |
</label> |
| 424 |
|
| 425 |
<input |
| 426 |
type="text" |
| 427 |
name="<?php echo $type; ?>_first_name" |
| 428 |
id="<?php echo $type; ?>_first_name" |
| 429 |
autocomplete="given-name" |
| 430 |
placeholder="<?php echo esc_attr__('First Name', 'fluent-cart'); ?>" |
| 431 |
data-required="yes" |
| 432 |
data-type="input" |
| 433 |
> |
| 434 |
</div> |
| 435 |
|
| 436 |
<?php if (CheckoutFieldsSchema::isLastNameEnabled()) : ?> |
| 437 |
<div class="fct_input_wrapper" id="<?php echo $type; ?>_last_name_wrapper"> |
| 438 |
<label for="<?php echo $type; ?>_last_name" class="sr-only"> |
| 439 |
<?php echo esc_html__('Last Name', 'fluent-cart'); ?> |
| 440 |
</label> |
| 441 |
|
| 442 |
<input |
| 443 |
type="text" |
| 444 |
name="<?php echo $type; ?>_last_name" |
| 445 |
id="<?php echo $type; ?>_last_name" |
| 446 |
autocomplete="family-name" |
| 447 |
placeholder="<?php echo esc_attr__('Last Name', 'fluent-cart'); ?>" |
| 448 |
data-required="<?php echo CheckoutFieldsSchema::isLastNameRequired() ? 'yes' : 'no'; ?>" |
| 449 |
data-type="input" |
| 450 |
> |
| 451 |
</div> |
| 452 |
<?php endif; ?> |
| 453 |
|
| 454 |
<?php endif; |
| 455 |
} |
| 456 |
|
| 457 |
public function renderBusinessDetailsFields() |
| 458 |
{ |
| 459 |
if ($this->address_type !== 'billing') { |
| 460 |
return; |
| 461 |
} |
| 462 |
|
| 463 |
$fields = [ |
| 464 |
'company_name' => __('Company Name', 'fluent-cart'), |
| 465 |
'vat_number' => __('VAT/GST/Tax Number', 'fluent-cart'), |
| 466 |
'legal_registration_id' => __('Legal Registration ID', 'fluent-cart'), |
| 467 |
]; |
| 468 |
|
| 469 |
$visibleFields = []; |
| 470 |
foreach ($fields as $fieldKey => $label) { |
| 471 |
$requirement = Arr::get($this->requirements_fields, $fieldKey); |
| 472 |
|
| 473 |
if (empty($requirement)) { |
| 474 |
continue; |
| 475 |
} |
| 476 |
|
| 477 |
$visibleFields[$fieldKey] = $label; |
| 478 |
} |
| 479 |
|
| 480 |
if (empty($visibleFields)) { |
| 481 |
return; |
| 482 |
} |
| 483 |
|
| 484 |
?> |
| 485 |
<div id="<?php echo esc_attr($this->address_type); ?>_business_details_section" |
| 486 |
data-fluent-cart-checkout-page-form-section="" |
| 487 |
class="fct_checkout_form_section additional-address-field"> |
| 488 |
<div class="fct_form_section_header"> |
| 489 |
<h4 class="fct_form_section_header_label"><?php echo esc_html__('Business Details', 'fluent-cart'); ?></h4> |
| 490 |
</div> |
| 491 |
|
| 492 |
<div class="fct_form_section_body"> |
| 493 |
<div class="fct_checkout_input_group"> |
| 494 |
<?php |
| 495 |
foreach ($visibleFields as $fieldKey => $label) { |
| 496 |
$requirement = Arr::get($this->requirements_fields, $fieldKey); |
| 497 |
$fieldId = $this->address_type . '_' . $fieldKey; |
| 498 |
$isRequired = $requirement === 'required'; |
| 499 |
$placeholder = $label . ($isRequired ? ' *' : ''); |
| 500 |
?> |
| 501 |
<div data-fluent-cart-checkout-page-form-input-wrapper="" class="fct_input_wrapper " |
| 502 |
id="<?php echo esc_attr($fieldId); ?>_wrapper"> |
| 503 |
<label for="<?php echo esc_attr($fieldId); ?>" class="sr-only"> |
| 504 |
<?php echo esc_html($label); ?> |
| 505 |
</label> |
| 506 |
|
| 507 |
<input type="text" name="<?php echo esc_attr($fieldId); ?>" |
| 508 |
autocomplete="off" placeholder="<?php echo esc_attr($placeholder); ?>" |
| 509 |
data-required="<?php echo $isRequired ? 'yes' : 'no'; ?>" data-type="input" |
| 510 |
id="<?php echo esc_attr($fieldId); ?>"> |
| 511 |
</div> |
| 512 |
<?php |
| 513 |
} |
| 514 |
?> |
| 515 |
</div> |
| 516 |
</div> |
| 517 |
</div> |
| 518 |
<?php |
| 519 |
} |
| 520 |
} |
| 521 |
|