PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.4.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.4.1
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Services / Renderer / CheckoutFieldsSchema.php

CheckoutFieldsSchema.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.4.1, at app/Services/Renderer/CheckoutFieldsSchema.php

830 lines 30.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Renderer;
4
5 use FluentCart\Api\Resource\CustomerResource;
6 use FluentCart\Api\Resource\FrontendResource\CustomerAddressResource;
7 use FluentCart\App\App;
8 use FluentCart\App\Helpers\Helper;
9 use FluentCart\App\Services\Localization\LocalizationManager;
10 use FluentCart\Framework\Support\Arr;
11
12 class CheckoutFieldsSchema
13 {
14
15 public static function titleMap(): array
16 {
17 return [
18 'full_name' => __('Name', 'fluent-cart'),
19 'first_name' => __('First Name', 'fluent-cart'),
20 'last_name' => __('Last Name', 'fluent-cart'),
21 'email' => __('Email', 'fluent-cart'),
22 ];
23 }
24
25 public static function typeMap(): array
26 {
27 return [
28 'full_name' => 'text',
29 'first_name' => 'text',
30 'last_name' => 'text',
31 'email' => 'email',
32 ];
33 }
34
35 private static function autocompleteMap(): array
36 {
37 return [
38 'full_name' => 'name',
39 'first_name' => 'given-name',
40 'last_name' => 'family-name',
41 'email' => 'email',
42 ];
43 }
44
45 public static function getNameEmailFieldsSchema($cart = null, $scope = 'render')
46 {
47
48 $fieldData = [];
49 if ($cart && $scope === 'render') {
50 $customerName = trim($cart->first_name . ' ' . $cart->last_name);
51 $customerEmail = $cart->email;
52 if (is_user_logged_in()) {
53 $user = wp_get_current_user();
54 $customerName = trim($user->first_name . ' ' . $user->last_name);
55 $fieldData['first_name'] = $user->first_name;
56 $fieldData['last_name'] = $user->last_name;
57 if (empty($customerName)) {
58 $customerName = $user->display_name;
59 }
60 $customerEmail = $user->user_email;
61 }
62
63 $fieldData['full_name'] = $customerName;
64 $fieldData['email'] = $customerEmail;
65
66 }
67
68 $fieldsSchema = self::getFieldsSettings();
69
70 $titleMap = static::titleMap();
71 $autocompleteMap = static::autocompleteMap();
72 $nameFields = [];
73 $infoFields = Arr::get($fieldsSchema, 'basic_info', []);
74 foreach ($infoFields as $fieldKey => $basicField) {
75 if (!isset($titleMap[$fieldKey])) {
76 continue;
77 }
78 if (Arr::get($basicField, 'enabled', 'no') !== 'yes') {
79 continue;
80 }
81 $key = 'billing_' . $fieldKey;
82 $isRequired = Arr::get($basicField, 'required', 'no') === 'yes' ? 'yes' : '';
83 $label = Arr::get($titleMap, $fieldKey);
84 $nameFields[$key] = [
85 'name' => $key,
86 'id' => $key,
87 'type' => 'text',
88 'data-type' => 'text',
89 'required' => $isRequired,
90 'label' => '',
91 'aria-label' => $label,
92 'placeholder' => $label . ($isRequired ? ' *' : ''),
93 'autocomplete' => isset($autocompleteMap[$fieldKey]) ? $autocompleteMap[$fieldKey] : 'on',
94 'value' => Arr::get($fieldData, $fieldKey)
95 ];
96 }
97
98 $nameFields = apply_filters('fluent_cart/checkout_page_name_fields_schema', $nameFields, [
99 'cart' => $cart,
100 'scope' => $scope
101 ]);
102
103
104 return [
105 'type' => 'section',
106 'title' => '',
107 'id' => 'billing_personal_information_section',
108 'fields' => $nameFields,
109 ];
110 }
111
112 public static function getAddressBaseFields($config, $scope = 'render')
113 {
114
115 $configDefaults = [
116 'type' => 'billing', // billing or shipping
117 'product_type' => 'digital', // digital or physical
118 'with_shipping' => false, // only for billing type, if true and type is billing, then shipping fields will be returned without full_name field
119 'full_name' => '',
120 'country' => '',
121 'address_1' => '',
122 'address_2' => '',
123 'state' => '',
124 'city' => '',
125 'postcode' => '',
126 'company_name' => '',
127 'phone' => '',
128 ];
129
130 $config = wp_parse_args($config, $configDefaults);
131
132 $selectedCountry = Arr::get($config, 'country');
133 if (empty($selectedCountry)) {
134 $HTTP_CF_IP_COUNTRY = Arr::get(App::request()->server(), 'HTTP_CF_IPCOUNTRY');
135 $selectedCountry = $HTTP_CF_IP_COUNTRY ?? $selectedCountry;
136 }
137
138 $states = [];
139 if (empty($config['state']) || empty($selectedCountry)) {
140 $states = [
141 [
142 'name' => __('Select an option', 'fluent-cart'),
143 'value' => ''
144 ]
145 ];
146 }
147
148 $addressLocale = [];
149 if (!empty($selectedCountry)) {
150 $states = array_merge($states, LocalizationManager::getInstance()->statesOptions($selectedCountry));
151 $addressLocale = LocalizationManager::getInstance()->addressLocales($selectedCountry);
152 }
153
154 $stateLabel = Arr::get($addressLocale, 'state.label', __('State', 'fluent-cart'));
155 $countries = [
156 [
157 'name' => __('Select a Country', 'fluent-cart'),
158 'value' => ''
159 ]
160 ];
161
162 $countries = array_merge($countries, Helper::getCountryList());
163
164 $type = Arr::get($config, 'type', 'billing'); // billing or shipping
165
166 if (!in_array($type, ['billing', 'shipping'])) {
167 $type = 'billing';
168 }
169
170
171 if (empty($states) && !Arr::get($addressLocale, 'state.hidden')) {
172 $stateInput = [
173 'name' => $type . '_state',
174 'id' => $type . '_state',
175 'type' => 'text',
176 'data-type' => 'text',
177 'label' => '',
178 'required' => 'yes',
179 'autocomplete' => 'address-level2',
180 'placeholder' => $stateLabel,
181 'aria-label' => $stateLabel,
182 'value' => $config['state'],
183 'wrapper_atts' => [
184 'id' => $type . '_state_wrapper'
185 ]
186 ];
187 } else {
188 $stateInput = [
189 'name' => $type . '_state',
190 'id' => $type . '_state',
191 'type' => 'select',
192 'data-type' => 'select',
193 'label' => '',
194 'options' => $states,
195 'required' => 'yes',
196 'autocomplete' => 'address-level2',
197 'placeholder' => $stateLabel,
198 'aria-label' => $stateLabel,
199 'value' => $config['state'],
200 'wrapper_atts' => [
201 'id' => $type . '_state_wrapper'
202 ]
203 ];
204 }
205
206 $fields = [
207 'full_name' => [
208 'id' => $type . '_full_name',
209 'name' => $type . '_full_name',
210 'type' => 'text',
211 'data-type' => 'text',
212 'label' => '',
213 'is_core' => 'yes',
214 'required' => 'yes',
215 'autocomplete' => 'given-name',
216 'value' => $config['full_name'],
217 'placeholder' => esc_attr__('Full Name', 'fluent-cart'),
218 'aria-label' => esc_attr__('Your Full Name', 'fluent-cart'),
219 ],
220 'country' => [
221 'name' => $type . '_country',
222 'id' => $type . '_country',
223 'type' => 'select',
224 'options' => $countries,
225 'data-type' => 'text',
226 'label' => '',
227 'aria-label' => esc_attr__('Country / Region', 'fluent-cart'),
228 'required' => 'yes',
229 'autocomplete' => 'country',
230 'placeholder' => esc_attr__('Country / Region', 'fluent-cart'),
231 'value' => $selectedCountry,
232 ],
233 'address_1' => [
234 'name' => $type . '_address_1',
235 'id' => $type . '_address_1',
236 'type' => 'text',
237 'data-type' => 'text',
238 'label' => '',
239 'aria-label' => esc_attr__('Street Address', 'fluent-cart'),
240 /* translators: use local order of street name and house number. */
241 'placeholder' => esc_attr__('Street Address', 'fluent-cart'),
242 'required' => 'yes',
243 'autocomplete' => 'address-line1',
244 'value' => $config['address_1'],
245 ],
246 'address_2' => [
247 'name' => $type . '_address_2',
248 'id' => $type . '_address_2',
249 'type' => 'text',
250 'data-type' => 'text',
251 'label' => '',
252 'aria-label' => esc_attr__('Apt, suite, unit', 'fluent-cart'),
253 'label_class' => array(''),
254 'placeholder' => esc_attr__('Apt, suite, unit', 'fluent-cart'),
255 'autocomplete' => 'address-line2',
256 'value' => $config['address_2'],
257 ],
258 'state' => $stateInput,
259 'city' => [
260 'name' => $type . '_city',
261 'id' => $type . '_city',
262 'type' => 'text',
263 'data-type' => 'text',
264 'label' => '',
265 'aria-label' => esc_attr__('Town / City', 'fluent-cart'),
266 'required' => 'yes',
267 'autocomplete' => 'address-level2',
268 'placeholder' => esc_attr__('Town / City', 'fluent-cart'),
269 'value' => $config['city'],
270 ],
271 'postcode' => [
272 'name' => $type . '_postcode',
273 'id' => $type . '_postcode',
274 'type' => 'text',
275 'data-type' => 'text',
276 'label' => '',
277 'aria-label' => esc_attr__('Postal / ZIP Code', 'fluent-cart'),
278 'required' => 'yes',
279 'validate' => array('postcode'),
280 'autocomplete' => 'postal-code',
281 'placeholder' => esc_attr__('Postcode / ZIP', 'fluent-cart'),
282 'value' => $config['postcode'],
283 ],
284 'phone' => [
285 'name' => $type . '_phone',
286 'id' => $type . '_phone',
287 'type' => 'tel',
288 'data-type' => 'text',
289 'label' => '',
290 'aria-label' => esc_attr__('Phone number', 'fluent-cart'),
291 'placeholder' => esc_attr__('Phone number', 'fluent-cart'),
292 'autocomplete' => 'tel',
293 'value' => $config['phone'],
294 ],
295 'company_name' => [
296 'name' => $type . '_company_name',
297 'id' => $type . '_company_name',
298 'type' => 'text',
299 'data-type' => 'text',
300 'label' => '',
301 'aria-label' => esc_attr__('Company name', 'fluent-cart'),
302 'placeholder' => esc_attr__('Company name', 'fluent-cart'),
303 'autocomplete' => 'organization',
304 'value' => $config['company_name'],
305 ],
306 ];
307
308 if ($type === 'billing') {
309 unset($fields['full_name']);
310 }
311
312 $requirementsFields = [];
313 if ($scope === 'render') {
314 $requirementsFields = self::getCheckoutFieldsRequirements($type, $config['product_type'], $config['with_shipping']);
315
316 $formattedFields = [];
317 foreach ($fields as $key => $field) {
318 $requirement = Arr::get($requirementsFields, $key, '');
319 if (!$requirement) {
320 continue;
321 }
322 if ($requirement === 'required') {
323 $field['required'] = 'yes';
324 $field['placeholder'] = $field['placeholder'] . ' *';
325 } else {
326 unset($field['required']);
327 }
328 $formattedFields[$key] = $field;
329 }
330 $fields = $formattedFields;
331 }
332
333 return apply_filters('fluent_cart/fields/address_base_fields', $fields, [
334 'config' => $config,
335 'scope' => $scope,
336 'requirements' => $requirementsFields
337 ]);
338 }
339
340
341 private static function getRequirementType($config, $key)
342 {
343 $enabled = Arr::get($config, $key . '.enabled', 'no') === 'yes';
344 if (!$enabled) {
345 return '';
346 }
347
348 if (Arr::get($config, $key . '.required', 'no') === 'yes') {
349 return 'required';
350 }
351
352 return 'optional';
353 }
354
355 public static function getCheckoutFieldsRequirements($addressType = 'billing', $productType = 'digital', $withShipping = false) // digital or physical
356 {
357 $fieldsConfig = self::getFieldsSettings();
358
359
360 $shippingConfig = Arr::get($fieldsConfig, 'shipping_address', []);
361 $billingConfig = Arr::get($fieldsConfig, 'billing_address', []);
362 $businessConfig = Arr::get($fieldsConfig, 'business_details', []);
363 $basicConfig = Arr::get($fieldsConfig, 'basic_info', []);
364 $basicSchema = [];
365
366 if (static::isFullNameRequired()) {
367 $basicSchema = [
368 'full_name' => [
369 'billing' => '',
370 'shipping' => 'required'
371 ],
372 ];
373 } else {
374 $basicSchema = [
375 'first_name' => [
376 'billing' => 'required',
377 'shipping' => 'required'
378 ],
379 ];
380
381 if (static::isLastNameEnabled()) {
382 $basicSchema['last_name'] = [
383 'billing' => static::isLastNameRequired() ? 'required' : '',
384 'shipping' => static::isLastNameRequired() ? 'required' : ''
385 ];
386 }
387 }
388
389 $dataConfig = [
390 'country' => [
391 'billing' => self::getRequirementType($billingConfig, 'country'),
392 'shipping' => self::getRequirementType($shippingConfig, 'country')
393 ],
394 'address_1' => [
395 'billing' => self::getRequirementType($billingConfig, 'address_1'),
396 'shipping' => self::getRequirementType($shippingConfig, 'address_1')
397 ],
398 'address_2' => [
399 'billing' => self::getRequirementType($billingConfig, 'address_2'),
400 'shipping' => self::getRequirementType($shippingConfig, 'address_2')
401 ],
402 'state' => [
403 'billing' => self::getRequirementType($billingConfig, 'state'),
404 'shipping' => self::getRequirementType($shippingConfig, 'state')
405 ],
406 'city' => [
407 'billing' => self::getRequirementType($billingConfig, 'city'),
408 'shipping' => self::getRequirementType($shippingConfig, 'city')
409 ],
410 'postcode' => [
411 'billing' => self::getRequirementType($billingConfig, 'postcode'),
412 'shipping' => self::getRequirementType($shippingConfig, 'postcode')
413 ],
414 'vat_number' => [
415 'billing' => self::getRequirementType($businessConfig, 'vat_number'),
416 'shipping' => ''
417 ],
418 'phone' => [
419 'billing' => self::getRequirementType($billingConfig, 'phone'),
420 'shipping' => self::getRequirementType($shippingConfig, 'phone')
421 ]
422 ];
423 $dataConfig = array_merge(
424 $basicSchema,
425 $dataConfig
426 );
427
428
429 if ($withShipping && $addressType == 'billing') {
430 // now we have to merge the shipping fields requirements with billing fields requirements
431 foreach ($dataConfig as $key => $config) {
432 if ($config[$addressType] === 'required') {
433 $dataConfig[$key][$addressType] = 'required';
434 } elseif ($config[$addressType] === 'optional' && $dataConfig[$key][$addressType] !== 'required') {
435 $dataConfig[$key][$addressType] = 'optional';
436 } else {
437 $dataConfig[$key][$addressType] = '';
438 }
439 }
440 }
441
442 $formattedReturn = [];
443 foreach ($dataConfig as $key => $config) {
444 if (Arr::get($config, $addressType)) {
445 $formattedReturn[$key] = $config[$addressType];
446 }
447 }
448
449 return $formattedReturn;
450 }
451
452 public static function getFieldsSchemaConfig()
453 {
454 return [
455 'basic_info' => [
456 'full_name' => [
457 'label' => __('Full Name', 'fluent-cart'),
458 'help_text' => __('Enabling First/Last name will replace the default Full Name.', 'fluent-cart'),
459 'type' => 'text',
460 'can_alter' => 'no',
461 ],
462 'first_name' => [
463 'label' => __('First Name', 'fluent-cart'),
464 'type' => 'text',
465 'can_alter' => 'yes',
466 ],
467 'last_name' => [
468 'label' => __('Last Name', 'fluent-cart'),
469 'type' => 'text',
470 'can_alter' => 'yes',
471 ],
472 'email' => [
473 'label' => __('Email Address', 'fluent-cart'),
474 'type' => 'email',
475 'can_alter' => 'no',
476 ],
477 ],
478 'business_details' => [
479 'company_name' => [
480 'label' => __('Company', 'fluent-cart'),
481 'type' => 'text',
482 'can_alter' => 'yes',
483 ],
484 'vat_number' => [
485 'label' => __('VAT/GST/Tax Number', 'fluent-cart'),
486 'help_text' => __('Show a VAT/GST/Tax number field at checkout for customers to provide their tax ID.', 'fluent-cart'),
487 'type' => 'text',
488 'can_alter' => 'yes',
489 ],
490 'legal_registration_id' => [
491 'label' => __('Legal Registration ID', 'fluent-cart'),
492 'help_text' => __('Show a legal registration / business ID field at checkout (e.g. company registration number).', 'fluent-cart'),
493 'type' => 'text',
494 'can_alter' => 'yes',
495 ],
496 ],
497 'billing_address' => [
498 'country' => [
499 'label' => __('Country', 'fluent-cart'),
500 'type' => 'text',
501 'can_alter' => 'yes',
502 ],
503 'state' => [
504 'label' => __('State', 'fluent-cart'),
505 'type' => 'text',
506 'can_alter' => 'yes',
507 ],
508 'address_1' => [
509 'label' => __('Street Address', 'fluent-cart'),
510 'type' => 'text',
511 'can_alter' => 'yes',
512 ],
513 'address_2' => [
514 'label' => __('Apt, suite, unit', 'fluent-cart'),
515 'type' => 'text',
516 'can_alter' => 'yes',
517 ],
518 'city' => [
519 'label' => __('City', 'fluent-cart'),
520 'type' => 'text',
521 'can_alter' => 'yes',
522 ],
523 'postcode' => [
524 'label' => __('Post Code', 'fluent-cart'),
525 'type' => 'text',
526 'can_alter' => 'yes',
527 ],
528 'phone' => [
529 'label' => __('Phone', 'fluent-cart'),
530 'type' => 'text',
531 'can_alter' => 'yes',
532 ]
533 ],
534 'shipping_address' => [
535 'full_name' => [
536 'label' => __('Full Name', 'fluent-cart'),
537 'type' => 'text',
538 'can_alter' => 'no',
539 ],
540 'country' => [
541 'label' => __('Country', 'fluent-cart'),
542 'type' => 'text',
543 'can_alter' => 'yes',
544 ],
545 'state' => [
546 'label' => __('State', 'fluent-cart'),
547 'type' => 'text',
548 'can_alter' => 'yes',
549 ],
550 'address_1' => [
551 'label' => __('Street Address', 'fluent-cart'),
552 'type' => 'text',
553 'can_alter' => 'yes',
554 ],
555 'address_2' => [
556 'label' => __('Apt, suite, unit', 'fluent-cart'),
557 'type' => 'text',
558 'can_alter' => 'yes',
559 ],
560 'city' => [
561 'label' => __('City', 'fluent-cart'),
562 'type' => 'text',
563 'can_alter' => 'yes',
564 ],
565 'postcode' => [
566 'label' => __('Post Code', 'fluent-cart'),
567 'type' => 'text',
568 'can_alter' => 'yes',
569 ],
570 'phone' => [
571 'label' => __('Phone', 'fluent-cart'),
572 'type' => 'text',
573 'can_alter' => 'yes',
574 ]
575 ],
576 'agree_terms' => [
577 'label' => __('Agree Terms and Conditions', 'fluent-cart'),
578 'type' => 'checkbox',
579 'can_alter' => 'yes',
580 ]
581 ];
582 }
583
584 public static function getFieldsSettings()
585 {
586 static $cached = null;
587 if ($cached !== null) {
588 return $cached;
589 }
590
591 $defaults = [
592 'basic_info' => [
593 'full_name' => [
594 'required' => 'yes',
595 'enabled' => 'yes'
596 ],
597 'first_name' => [
598 'required' => 'no',
599 'enabled' => 'no'
600 ],
601 'last_name' => [
602 'required' => 'no',
603 'enabled' => 'no'
604 ],
605 'email' => [
606 'required' => 'yes',
607 'enabled' => 'yes'
608 ],
609 ],
610 'business_details' => [
611 'company_name' => [
612 'required' => 'no',
613 'enabled' => 'no'
614 ],
615 'vat_number' => [
616 'required' => 'no',
617 'enabled' => 'no'
618 ],
619 'legal_registration_id' => [
620 'required' => 'no',
621 'enabled' => 'no'
622 ],
623 ],
624 'billing_address' => [
625 'country' => [
626 'required' => 'yes',
627 'enabled' => 'yes'
628 ],
629 'state' => [
630 'required' => 'yes',
631 'enabled' => 'yes'
632 ],
633 'address_1' => [
634 'required' => 'yes',
635 'enabled' => 'yes'
636 ],
637 'address_2' => [
638 'required' => 'no',
639 'enabled' => 'yes'
640 ],
641 'city' => [
642 'required' => 'yes',
643 'enabled' => 'yes'
644 ],
645 'postcode' => [
646 'required' => 'yes',
647 'enabled' => 'yes'
648 ],
649 'phone' => [
650 'required' => 'no',
651 'enabled' => 'no'
652 ],
653 'company_name' => [
654 'required' => 'no',
655 'enabled' => 'no'
656 ]
657 ],
658 'shipping_address' => [
659 'full_name' => [
660 'required' => 'yes',
661 'enabled' => 'yes',
662 ],
663 'country' => [
664 'required' => 'yes',
665 'enabled' => 'yes'
666 ],
667 'state' => [
668 'required' => 'yes',
669 'enabled' => 'yes'
670 ],
671 'address_1' => [
672 'required' => 'yes',
673 'enabled' => 'yes'
674 ],
675 'address_2' => [
676 'required' => 'no',
677 'enabled' => 'yes'
678 ],
679 'city' => [
680 'required' => 'yes',
681 'enabled' => 'yes'
682 ],
683 'postcode' => [
684 'required' => 'yes',
685 'enabled' => 'yes'
686 ],
687 'phone' => [
688 'required' => 'no',
689 'enabled' => 'no'
690 ],
691 'company_name' => [
692 'required' => 'no',
693 'enabled' => 'no'
694 ]
695 ],
696 'agree_terms' => [
697 'required' => 'no',
698 'enabled' => 'no',
699 'text' => ''
700 ]
701 ];
702
703 $savedConfig = fluent_cart_get_option('_fc_checkout_fields', []);
704
705 if (!$savedConfig || !is_array($savedConfig)) {
706 return $defaults;
707 }
708
709 // Migrate company_name and vat_number from the old basic_info location for existing stores
710 if (empty($savedConfig['business_details']) && !empty($savedConfig['basic_info'])) {
711 if (!empty($savedConfig['basic_info']['company_name'])) {
712 $savedConfig['business_details']['company_name'] = $savedConfig['basic_info']['company_name'];
713 }
714 if (!empty($savedConfig['basic_info']['vat_number'])) {
715 $savedConfig['business_details']['vat_number'] = $savedConfig['basic_info']['vat_number'];
716 }
717 }
718
719 $groupFields = ['basic_info', 'billing_address', 'shipping_address', 'business_details'];
720
721 foreach ($defaults as $key => $default) {
722 $savedValues = Arr::get($savedConfig, $key, []);
723 if (in_array($key, $groupFields)) {
724 $savedValues = Arr::only($savedValues, array_keys($default));
725 }
726
727 $defaults[$key] = wp_parse_args($savedValues, $default);
728 }
729
730 return ($cached = $defaults);
731 }
732
733 public static function isTermsRequired(): bool
734 {
735 $fieldSettings = self::getFieldsSettings();
736 return Arr::get($fieldSettings, 'agree_terms.enabled') === 'yes'
737 && Arr::get($fieldSettings, 'agree_terms.required') === 'yes';
738 }
739
740 public static function isTermsVisible(): bool
741 {
742 $fieldSettings = self::getFieldsSettings();
743 return Arr::get($fieldSettings, 'agree_terms.enabled') === 'yes';
744 }
745
746 public static function getTermsText()
747 {
748 $text = Arr::get(self::getFieldsSettings(), 'agree_terms.text', '');
749
750 if (!$text) {
751 $text = __('I agree to the terms and conditions.', 'fluent-cart');
752 }
753
754 return $text;
755 }
756
757 public static function isFirstNameEnabled(): bool
758 {
759 $fieldsSchema = self::getFieldsSettings();
760 return Arr::get($fieldsSchema, 'basic_info.first_name.enabled') === 'yes';
761
762 }
763
764 public static function isLastNameEnabled(): bool
765 {
766 $fieldsSchema = self::getFieldsSettings();
767 return Arr::get($fieldsSchema, 'basic_info.last_name.enabled') === 'yes';
768 }
769
770 public static function isLastNameRequired(): bool
771 {
772 $fieldsSchema = self::getFieldsSettings();
773 return Arr::get($fieldsSchema, 'basic_info.last_name.required') === 'yes';
774 }
775
776 public static function isFullNameRequired(): bool
777 {
778
779 $isFirstNameEnabled = static::isFirstNameEnabled();
780 $isLastNameEnabled = static::isLastNameEnabled();
781 return !($isFirstNameEnabled || $isLastNameEnabled);
782 }
783
784 public static function isVatNumberEnabled(): bool
785 {
786 $fieldSettings = self::getFieldsSettings();
787 return Arr::get($fieldSettings, 'business_details.vat_number.enabled') === 'yes';
788 }
789
790 public static function isCompanyNameEnabled(): bool
791 {
792 $fieldSettings = self::getFieldsSettings();
793 return Arr::get($fieldSettings, 'business_details.company_name.enabled') === 'yes';
794 }
795
796 public static function isCompanyNameRequired(): bool
797 {
798 $fieldSettings = self::getFieldsSettings();
799 return Arr::get($fieldSettings, 'business_details.company_name.enabled') === 'yes'
800 && Arr::get($fieldSettings, 'business_details.company_name.required') === 'yes';
801 }
802
803 public static function isVatNumberRequired(): bool
804 {
805 $fieldSettings = self::getFieldsSettings();
806 return Arr::get($fieldSettings, 'business_details.vat_number.enabled') === 'yes'
807 && Arr::get($fieldSettings, 'business_details.vat_number.required') === 'yes';
808 }
809
810 public static function isLegalRegistrationIdEnabled(): bool
811 {
812 $fieldSettings = self::getFieldsSettings();
813 return Arr::get($fieldSettings, 'business_details.legal_registration_id.enabled') === 'yes';
814 }
815
816 public static function isLegalRegistrationIdRequired(): bool
817 {
818 $fieldSettings = self::getFieldsSettings();
819 return Arr::get($fieldSettings, 'business_details.legal_registration_id.enabled') === 'yes'
820 && Arr::get($fieldSettings, 'business_details.legal_registration_id.required') === 'yes';
821 }
822
823 public static function hasAnyBusinessFields(): bool
824 {
825 return static::isCompanyNameEnabled()
826 || static::isVatNumberEnabled()
827 || static::isLegalRegistrationIdEnabled();
828 }
829 }
830