PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.3
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.3
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.5.3, at app/Services/Renderer/CheckoutFieldsSchema.php

845 lines 31.3 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 'b2b_only_mode' => [
497 'label' => __('B2B Only Mode', 'fluent-cart'),
498 'help_text' => __('When enabled, the B2B purchase toggle is hidden and business fields are always shown to all customers.', 'fluent-cart'),
499 'type' => 'checkbox',
500 'can_alter' => 'yes',
501 ],
502 ],
503 'billing_address' => [
504 'country' => [
505 'label' => __('Country', 'fluent-cart'),
506 'type' => 'text',
507 'can_alter' => 'yes',
508 ],
509 'state' => [
510 'label' => __('State', 'fluent-cart'),
511 'type' => 'text',
512 'can_alter' => 'yes',
513 ],
514 'address_1' => [
515 'label' => __('Street Address', 'fluent-cart'),
516 'type' => 'text',
517 'can_alter' => 'yes',
518 ],
519 'address_2' => [
520 'label' => __('Apt, suite, unit', 'fluent-cart'),
521 'type' => 'text',
522 'can_alter' => 'yes',
523 ],
524 'city' => [
525 'label' => __('City', 'fluent-cart'),
526 'type' => 'text',
527 'can_alter' => 'yes',
528 ],
529 'postcode' => [
530 'label' => __('Post Code', 'fluent-cart'),
531 'type' => 'text',
532 'can_alter' => 'yes',
533 ],
534 'phone' => [
535 'label' => __('Phone', 'fluent-cart'),
536 'type' => 'text',
537 'can_alter' => 'yes',
538 ]
539 ],
540 'shipping_address' => [
541 'full_name' => [
542 'label' => __('Full Name', 'fluent-cart'),
543 'type' => 'text',
544 'can_alter' => 'no',
545 ],
546 'country' => [
547 'label' => __('Country', 'fluent-cart'),
548 'type' => 'text',
549 'can_alter' => 'yes',
550 ],
551 'state' => [
552 'label' => __('State', 'fluent-cart'),
553 'type' => 'text',
554 'can_alter' => 'yes',
555 ],
556 'address_1' => [
557 'label' => __('Street Address', 'fluent-cart'),
558 'type' => 'text',
559 'can_alter' => 'yes',
560 ],
561 'address_2' => [
562 'label' => __('Apt, suite, unit', 'fluent-cart'),
563 'type' => 'text',
564 'can_alter' => 'yes',
565 ],
566 'city' => [
567 'label' => __('City', 'fluent-cart'),
568 'type' => 'text',
569 'can_alter' => 'yes',
570 ],
571 'postcode' => [
572 'label' => __('Post Code', 'fluent-cart'),
573 'type' => 'text',
574 'can_alter' => 'yes',
575 ],
576 'phone' => [
577 'label' => __('Phone', 'fluent-cart'),
578 'type' => 'text',
579 'can_alter' => 'yes',
580 ]
581 ],
582 'agree_terms' => [
583 'label' => __('Agree Terms and Conditions', 'fluent-cart'),
584 'type' => 'checkbox',
585 'can_alter' => 'yes',
586 ]
587 ];
588 }
589
590 public static function getFieldsSettings()
591 {
592 static $cached = null;
593 if ($cached !== null) {
594 return $cached;
595 }
596
597 $defaults = [
598 'basic_info' => [
599 'full_name' => [
600 'required' => 'yes',
601 'enabled' => 'yes'
602 ],
603 'first_name' => [
604 'required' => 'no',
605 'enabled' => 'no'
606 ],
607 'last_name' => [
608 'required' => 'no',
609 'enabled' => 'no'
610 ],
611 'email' => [
612 'required' => 'yes',
613 'enabled' => 'yes'
614 ],
615 ],
616 'business_details' => [
617 'company_name' => [
618 'required' => 'no',
619 'enabled' => 'no'
620 ],
621 'vat_number' => [
622 'required' => 'no',
623 'enabled' => 'no'
624 ],
625 'legal_registration_id' => [
626 'required' => 'no',
627 'enabled' => 'no'
628 ],
629 'b2b_only_mode' => [
630 'enabled' => 'no',
631 ],
632 ],
633 'billing_address' => [
634 'country' => [
635 'required' => 'yes',
636 'enabled' => 'yes'
637 ],
638 'state' => [
639 'required' => 'yes',
640 'enabled' => 'yes'
641 ],
642 'address_1' => [
643 'required' => 'yes',
644 'enabled' => 'yes'
645 ],
646 'address_2' => [
647 'required' => 'no',
648 'enabled' => 'yes'
649 ],
650 'city' => [
651 'required' => 'yes',
652 'enabled' => 'yes'
653 ],
654 'postcode' => [
655 'required' => 'yes',
656 'enabled' => 'yes'
657 ],
658 'phone' => [
659 'required' => 'no',
660 'enabled' => 'no'
661 ],
662 'company_name' => [
663 'required' => 'no',
664 'enabled' => 'no'
665 ]
666 ],
667 'shipping_address' => [
668 'full_name' => [
669 'required' => 'yes',
670 'enabled' => 'yes',
671 ],
672 'country' => [
673 'required' => 'yes',
674 'enabled' => 'yes'
675 ],
676 'state' => [
677 'required' => 'yes',
678 'enabled' => 'yes'
679 ],
680 'address_1' => [
681 'required' => 'yes',
682 'enabled' => 'yes'
683 ],
684 'address_2' => [
685 'required' => 'no',
686 'enabled' => 'yes'
687 ],
688 'city' => [
689 'required' => 'yes',
690 'enabled' => 'yes'
691 ],
692 'postcode' => [
693 'required' => 'yes',
694 'enabled' => 'yes'
695 ],
696 'phone' => [
697 'required' => 'no',
698 'enabled' => 'no'
699 ],
700 'company_name' => [
701 'required' => 'no',
702 'enabled' => 'no'
703 ]
704 ],
705 'agree_terms' => [
706 'required' => 'no',
707 'enabled' => 'no',
708 'text' => ''
709 ]
710 ];
711
712 $savedConfig = fluent_cart_get_option('_fc_checkout_fields', []);
713
714 if (!$savedConfig || !is_array($savedConfig)) {
715 return $defaults;
716 }
717
718 // Migrate company_name and vat_number from the old basic_info location for existing stores
719 if (empty($savedConfig['business_details']) && !empty($savedConfig['basic_info'])) {
720 if (!empty($savedConfig['basic_info']['company_name'])) {
721 $savedConfig['business_details']['company_name'] = $savedConfig['basic_info']['company_name'];
722 }
723 if (!empty($savedConfig['basic_info']['vat_number'])) {
724 $savedConfig['business_details']['vat_number'] = $savedConfig['basic_info']['vat_number'];
725 }
726 }
727
728 $groupFields = ['basic_info', 'billing_address', 'shipping_address', 'business_details'];
729
730 foreach ($defaults as $key => $default) {
731 $savedValues = Arr::get($savedConfig, $key, []);
732 if (in_array($key, $groupFields)) {
733 $savedValues = Arr::only($savedValues, array_keys($default));
734 }
735
736 $defaults[$key] = wp_parse_args($savedValues, $default);
737 }
738
739 return ($cached = $defaults);
740 }
741
742 public static function isTermsRequired(): bool
743 {
744 $fieldSettings = self::getFieldsSettings();
745 return Arr::get($fieldSettings, 'agree_terms.enabled') === 'yes'
746 && Arr::get($fieldSettings, 'agree_terms.required') === 'yes';
747 }
748
749 public static function isTermsVisible(): bool
750 {
751 $fieldSettings = self::getFieldsSettings();
752 return Arr::get($fieldSettings, 'agree_terms.enabled') === 'yes';
753 }
754
755 public static function getTermsText()
756 {
757 $text = Arr::get(self::getFieldsSettings(), 'agree_terms.text', '');
758
759 if (!$text) {
760 $text = __('I agree to the terms and conditions.', 'fluent-cart');
761 }
762
763 return $text;
764 }
765
766 public static function isFirstNameEnabled(): bool
767 {
768 $fieldsSchema = self::getFieldsSettings();
769 return Arr::get($fieldsSchema, 'basic_info.first_name.enabled') === 'yes';
770
771 }
772
773 public static function isLastNameEnabled(): bool
774 {
775 $fieldsSchema = self::getFieldsSettings();
776 return Arr::get($fieldsSchema, 'basic_info.last_name.enabled') === 'yes';
777 }
778
779 public static function isLastNameRequired(): bool
780 {
781 $fieldsSchema = self::getFieldsSettings();
782 return Arr::get($fieldsSchema, 'basic_info.last_name.required') === 'yes';
783 }
784
785 public static function isFullNameRequired(): bool
786 {
787
788 $isFirstNameEnabled = static::isFirstNameEnabled();
789 $isLastNameEnabled = static::isLastNameEnabled();
790 return !($isFirstNameEnabled || $isLastNameEnabled);
791 }
792
793 public static function isVatNumberEnabled(): bool
794 {
795 $fieldSettings = self::getFieldsSettings();
796 return Arr::get($fieldSettings, 'business_details.vat_number.enabled') === 'yes';
797 }
798
799 public static function isCompanyNameEnabled(): bool
800 {
801 $fieldSettings = self::getFieldsSettings();
802 return Arr::get($fieldSettings, 'business_details.company_name.enabled') === 'yes';
803 }
804
805 public static function isCompanyNameRequired(): bool
806 {
807 $fieldSettings = self::getFieldsSettings();
808 return Arr::get($fieldSettings, 'business_details.company_name.enabled') === 'yes'
809 && Arr::get($fieldSettings, 'business_details.company_name.required') === 'yes';
810 }
811
812 public static function isVatNumberRequired(): bool
813 {
814 $fieldSettings = self::getFieldsSettings();
815 return Arr::get($fieldSettings, 'business_details.vat_number.enabled') === 'yes'
816 && Arr::get($fieldSettings, 'business_details.vat_number.required') === 'yes';
817 }
818
819 public static function isLegalRegistrationIdEnabled(): bool
820 {
821 $fieldSettings = self::getFieldsSettings();
822 return Arr::get($fieldSettings, 'business_details.legal_registration_id.enabled') === 'yes';
823 }
824
825 public static function isLegalRegistrationIdRequired(): bool
826 {
827 $fieldSettings = self::getFieldsSettings();
828 return Arr::get($fieldSettings, 'business_details.legal_registration_id.enabled') === 'yes'
829 && Arr::get($fieldSettings, 'business_details.legal_registration_id.required') === 'yes';
830 }
831
832 public static function isB2BOnlyMode(): bool
833 {
834 $fieldSettings = self::getFieldsSettings();
835 return Arr::get($fieldSettings, 'business_details.b2b_only_mode.enabled') === 'yes';
836 }
837
838 public static function hasAnyBusinessFields(): bool
839 {
840 return static::isCompanyNameEnabled()
841 || static::isVatNumberEnabled()
842 || static::isLegalRegistrationIdEnabled();
843 }
844 }
845