PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.38
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.38
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / widgets / Pricing_Calculator / Pricing_Calculator.php

Pricing_Calculator.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.38, at includes/widgets/Pricing_Calculator/Pricing_Calculator.php

1,963 lines 70.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace King_Addons;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Widget_Base;
7 use Elementor\Group_Control_Typography;
8 use Elementor\Group_Control_Background;
9 use Elementor\Group_Control_Box_Shadow;
10 use Elementor\Repeater;
11 use Elementor\Group_Control_Border;
12
13 if (!defined('ABSPATH')) {
14 exit; // Exit if accessed directly.
15 }
16
17
18
19 class Pricing_Calculator extends Widget_Base
20 {
21
22
23 public function get_name(): string
24 {
25 return 'king-addons-pricing-calculator';
26 }
27
28 public function get_title(): string
29 {
30 return esc_html__('Pricing Calculator', 'king-addons');
31 }
32
33 public function get_icon(): string
34 {
35 return 'king-addons-icon king-addons-pricing-calculator';
36 }
37
38 public function get_style_depends(): array
39 {
40 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-pricing-calculator-style'];
41 }
42
43 public function get_script_depends(): array
44 {
45 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-pricing-calculator-script'];
46 }
47
48 public function get_categories(): array
49 {
50 return ['king-addons'];
51 }
52
53 public function get_keywords(): array
54 {
55 return [
56 'price',
57 'pricing',
58 'calculator',
59 'pricing calculator',
60 'quote',
61 'estimate',
62 'king addons',
63 'king',
64 'addons',
65 'kingaddons',
66 'king-addons'
67 ];
68 }
69
70 public function get_custom_help_url()
71 {
72 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
73 }
74
75 protected function register_controls()
76 {
77 $this->start_controls_section(
78 'section_pricing_calculator',
79 [
80 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Pricing Calculator', 'king-addons'),
81 ]
82 );
83
84 if (!king_addons_freemius()->can_use_premium_code__premium_only()) {
85 $this->add_control(
86 'pricing_calculator_pro_notice',
87 [
88 'type' => Controls_Manager::RAW_HTML,
89 'raw' => 'Advanced calculation formulas, conditional logic, and more options are available in the <strong><a href="https://kingaddons.com/pricing/?utm_source=kng-module-pricing-calculator-settings-upgrade-pro&utm_medium=plugin&utm_campaign=kng" target="_blank">Pro version</a></strong>',
90 'content_classes' => 'king-addons-pro-notice',
91 ]
92 );
93 }
94
95 $this->add_control(
96 'calculator_title',
97 [
98 'label' => esc_html__('Calculator Title', 'king-addons'),
99 'type' => Controls_Manager::TEXT,
100 'default' => esc_html__('Pricing Calculator', 'king-addons'),
101 'placeholder' => esc_html__('Enter title', 'king-addons'),
102 'label_block' => true,
103 ]
104 );
105
106 $this->add_control(
107 'calculator_description',
108 [
109 'label' => esc_html__('Description', 'king-addons'),
110 'type' => Controls_Manager::TEXTAREA,
111 'default' => esc_html__('Calculate the cost of your service', 'king-addons'),
112 'placeholder' => esc_html__('Enter description', 'king-addons'),
113 'rows' => 5,
114 ]
115 );
116
117 $this->end_controls_section();
118
119 // Calculator Fields Section
120 $this->start_controls_section(
121 'section_calculator_fields',
122 [
123 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Calculator Fields', 'king-addons'),
124 ]
125 );
126
127 $repeater = new Repeater();
128
129 $repeater->add_control(
130 'field_type',
131 [
132 'label' => esc_html__('Field Type', 'king-addons'),
133 'type' => Controls_Manager::SELECT,
134 'default' => 'number',
135 'options' => [
136 'number' => esc_html__('Number Input', 'king-addons'),
137 'range' => esc_html__('Range Slider', 'king-addons'),
138 'select' => esc_html__('Dropdown Select', 'king-addons'),
139 'radio' => esc_html__('Radio Buttons', 'king-addons'),
140 'checkbox' => esc_html__('Checkbox', 'king-addons'),
141 'switch' => esc_html__('Toggle Switch', 'king-addons')
142 ],
143 ]
144 );
145
146 $repeater->add_control(
147 'field_label',
148 [
149 'label' => esc_html__('Field Label', 'king-addons'),
150 'type' => Controls_Manager::TEXT,
151 'default' => esc_html__('Field Label', 'king-addons'),
152 'label_block' => true,
153 ]
154 );
155
156 $repeater->add_control(
157 'field_id',
158 [
159 'label' => esc_html__('Field ID', 'king-addons'),
160 'type' => Controls_Manager::TEXT,
161 'default' => '',
162 'placeholder' => esc_html__('e.g. quantity, service_type, rush_delivery', 'king-addons'),
163 'label_block' => true,
164 'description' => esc_html__('Set a unique ID for this field to use in formulas and conditions. Leave empty for auto-generated ID.', 'king-addons'),
165 ]
166 );
167
168 $repeater->add_control(
169 'field_description',
170 [
171 'label' => esc_html__('Description', 'king-addons'),
172 'type' => Controls_Manager::TEXT,
173 'default' => '',
174 'label_block' => true,
175 ]
176 );
177
178 $repeater->add_control(
179 'field_unit',
180 [
181 'label' => esc_html__('Unit Label', 'king-addons'),
182 'type' => Controls_Manager::TEXT,
183 'default' => '',
184 'placeholder' => esc_html__('e.g. hours, sq.ft, items', 'king-addons'),
185 'conditions' => [
186 'terms' => [
187 [
188 'name' => 'field_type',
189 'operator' => 'in',
190 'value' => ['number', 'range'],
191 ],
192 ],
193 ],
194 ]
195 );
196
197 $repeater->add_control(
198 'field_min',
199 [
200 'label' => esc_html__('Minimum Value', 'king-addons'),
201 'type' => Controls_Manager::NUMBER,
202 'default' => 0,
203 'conditions' => [
204 'terms' => [
205 [
206 'name' => 'field_type',
207 'operator' => 'in',
208 'value' => ['number', 'range'],
209 ],
210 ],
211 ],
212 ]
213 );
214
215 $repeater->add_control(
216 'field_max',
217 [
218 'label' => esc_html__('Maximum Value', 'king-addons'),
219 'type' => Controls_Manager::NUMBER,
220 'default' => 100,
221 'conditions' => [
222 'terms' => [
223 [
224 'name' => 'field_type',
225 'operator' => 'in',
226 'value' => ['number', 'range'],
227 ],
228 ],
229 ],
230 ]
231 );
232
233 $repeater->add_control(
234 'field_step',
235 [
236 'label' => esc_html__('Step', 'king-addons'),
237 'type' => Controls_Manager::NUMBER,
238 'default' => 1,
239 'min' => 0.01,
240 'conditions' => [
241 'terms' => [
242 [
243 'name' => 'field_type',
244 'operator' => 'in',
245 'value' => ['number', 'range'],
246 ],
247 ],
248 ],
249 ]
250 );
251
252 $repeater->add_control(
253 'field_default',
254 [
255 'label' => esc_html__('Default Value', 'king-addons'),
256 'type' => Controls_Manager::NUMBER,
257 'default' => 0,
258 'conditions' => [
259 'terms' => [
260 [
261 'name' => 'field_type',
262 'operator' => 'in',
263 'value' => ['number', 'range'],
264 ],
265 ],
266 ],
267 ]
268 );
269
270 $repeater->add_control(
271 'field_options',
272 [
273 'label' => esc_html__('Options (Value|Label|Price)', 'king-addons'),
274 'type' => Controls_Manager::TEXTAREA,
275 'default' => "option1|Option 1|10\noption2|Option 2|20\noption3|Option 3|30",
276 'description' => esc_html__('Enter one option per line in format: value|label|price', 'king-addons'),
277 'rows' => 5,
278 'conditions' => [
279 'terms' => [
280 [
281 'name' => 'field_type',
282 'operator' => 'in',
283 'value' => ['select', 'radio'],
284 ],
285 ],
286 ],
287 ]
288 );
289
290 $repeater->add_control(
291 'checkbox_value',
292 [
293 'label' => esc_html__('Checkbox Value', 'king-addons'),
294 'type' => Controls_Manager::NUMBER,
295 'default' => 10,
296 'conditions' => [
297 'terms' => [
298 [
299 'name' => 'field_type',
300 'operator' => 'in',
301 'value' => ['checkbox', 'switch'],
302 ],
303 ],
304 ],
305 ]
306 );
307
308 $repeater->add_control(
309 'field_price_type',
310 [
311 'label' => esc_html__('Price Calculation', 'king-addons'),
312 'type' => Controls_Manager::SELECT,
313 'default' => 'multiply',
314 'options' => [
315 'add' => esc_html__('Add Value', 'king-addons'),
316 'multiply' => esc_html__('Multiply Value', 'king-addons'),
317 'custom' => esc_html__('Custom Formula (Pro)', 'king-addons')
318 ],
319 'description' => esc_html__('Custom formula calculation is available in the Pro version. You can reference fields by their Field ID in custom formulas.', 'king-addons'),
320 ]
321 );
322
323 $repeater->add_control(
324 'field_price',
325 [
326 'label' => esc_html__('Price Amount', 'king-addons'),
327 'type' => Controls_Manager::NUMBER,
328 'default' => 10,
329 'conditions' => [
330 'terms' => [
331 [
332 'name' => 'field_price_type',
333 'operator' => '!==',
334 'value' => 'custom',
335 ],
336 [
337 'name' => 'field_type',
338 'operator' => '!in',
339 'value' => ['select', 'radio'],
340 ],
341 ],
342 ],
343 ]
344 );
345
346 $this->add_control(
347 'calculator_fields',
348 [
349 'label' => esc_html__('Calculator Fields', 'king-addons'),
350 'type' => Controls_Manager::REPEATER,
351 'fields' => $repeater->get_controls(),
352 'default' => [
353 [
354 'field_type' => 'range',
355 'field_label' => esc_html__('Quantity', 'king-addons'),
356 'field_unit' => esc_html__('items', 'king-addons'),
357 'field_min' => 1,
358 'field_max' => 100,
359 'field_step' => 1,
360 'field_default' => 10,
361 'field_price_type' => 'multiply',
362 'field_price' => 10,
363 ],
364 [
365 'field_type' => 'select',
366 'field_label' => esc_html__('Service Type', 'king-addons'),
367 'field_options' => "basic|Basic Service|50\nstandard|Standard Service|100\npremium|Premium Service|150",
368 'field_price_type' => 'add',
369 ],
370 [
371 'field_type' => 'checkbox',
372 'field_label' => esc_html__('Rush Delivery', 'king-addons'),
373 'checkbox_value' => 25,
374 'field_price_type' => 'add',
375 ],
376 ],
377 'title_field' => '{{{ field_label }}}',
378 ]
379 );
380
381 $this->end_controls_section();
382
383 // Calculation Settings Section
384 $this->start_controls_section(
385 'section_calculation_settings',
386 [
387 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Calculation Settings', 'king-addons'),
388 ]
389 );
390
391 $this->add_control(
392 'base_price',
393 [
394 'label' => esc_html__('Base Price', 'king-addons'),
395 'type' => Controls_Manager::NUMBER,
396 'default' => 0,
397 'min' => 0,
398 'step' => 0.01,
399 'description' => esc_html__('Starting price before any calculations', 'king-addons'),
400 ]
401 );
402
403 $this->add_control(
404 'price_prefix',
405 [
406 'label' => esc_html__('Price Prefix', 'king-addons'),
407 'type' => Controls_Manager::TEXT,
408 'default' => '$',
409 'placeholder' => esc_html__('Before price', 'king-addons'),
410 ]
411 );
412
413 $this->add_control(
414 'price_suffix',
415 [
416 'label' => esc_html__('Price Suffix', 'king-addons'),
417 'type' => Controls_Manager::TEXT,
418 'default' => '',
419 'placeholder' => esc_html__('After price', 'king-addons'),
420 ]
421 );
422
423 $this->add_control(
424 'decimal_places',
425 [
426 'label' => esc_html__('Decimal Places', 'king-addons'),
427 'type' => Controls_Manager::NUMBER,
428 'default' => 2,
429 'min' => 0,
430 'max' => 10,
431 'step' => 1,
432 'description' => esc_html__('Number of decimal places to display', 'king-addons'),
433 ]
434 );
435
436 $this->add_control(
437 'thousand_separator',
438 [
439 'label' => esc_html__('Thousand Separator', 'king-addons'),
440 'type' => Controls_Manager::TEXT,
441 'default' => ',',
442 'placeholder' => esc_html__(',', 'king-addons'),
443 ]
444 );
445
446 $this->add_control(
447 'decimal_separator',
448 [
449 'label' => esc_html__('Decimal Separator', 'king-addons'),
450 'type' => Controls_Manager::TEXT,
451 'default' => '.',
452 'placeholder' => esc_html__('.', 'king-addons'),
453 ]
454 );
455
456 $this->add_control(
457 'live_calculation',
458 [
459 'label' => esc_html__('Live Calculation', 'king-addons'),
460 'type' => Controls_Manager::SWITCHER,
461 'label_on' => esc_html__('Yes', 'king-addons'),
462 'label_off' => esc_html__('No', 'king-addons'),
463 'return_value' => 'yes',
464 'default' => 'yes',
465 'description' => esc_html__('Update price automatically when fields change', 'king-addons'),
466 ]
467 );
468
469 $this->add_control(
470 'enable_calculate_button',
471 [
472 'label' => esc_html__('Enable Calculate Button', 'king-addons'),
473 'type' => Controls_Manager::SWITCHER,
474 'label_on' => esc_html__('Yes', 'king-addons'),
475 'label_off' => esc_html__('No', 'king-addons'),
476 'return_value' => 'yes',
477 'default' => 'no',
478 'condition' => [
479 'live_calculation' => '',
480 ],
481 ]
482 );
483
484 $this->add_control(
485 'calculate_button_text',
486 [
487 'label' => esc_html__('Calculate Button Text', 'king-addons'),
488 'type' => Controls_Manager::TEXT,
489 'default' => esc_html__('Calculate', 'king-addons'),
490 'condition' => [
491 'enable_calculate_button' => 'yes',
492 ],
493 ]
494 );
495
496 $this->end_controls_section();
497
498 // Summary Section
499 $this->start_controls_section(
500 'section_summary',
501 [
502 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Summary & Results', 'king-addons'),
503 ]
504 );
505
506 $this->add_control(
507 'show_summary',
508 [
509 'label' => esc_html__('Show Calculation Summary', 'king-addons'),
510 'type' => Controls_Manager::SWITCHER,
511 'label_on' => esc_html__('Yes', 'king-addons'),
512 'label_off' => esc_html__('No', 'king-addons'),
513 'return_value' => 'yes',
514 'default' => 'yes',
515 'description' => esc_html__('Display breakdown of calculation', 'king-addons'),
516 ]
517 );
518
519 $this->add_control(
520 'summary_title',
521 [
522 'label' => esc_html__('Summary Title', 'king-addons'),
523 'type' => Controls_Manager::TEXT,
524 'default' => esc_html__('Summary', 'king-addons'),
525 'condition' => [
526 'show_summary' => 'yes',
527 ],
528 ]
529 );
530
531 $this->add_control(
532 'total_text',
533 [
534 'label' => esc_html__('Total Label', 'king-addons'),
535 'type' => Controls_Manager::TEXT,
536 'default' => esc_html__('Total Price:', 'king-addons'),
537 ]
538 );
539
540 $this->end_controls_section();
541
542 Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'king-addons-pricing-calculator', [
543 'Advanced Formula Calculation',
544 'Conditional Logic',
545 ]);
546
547 // Container Style
548 $this->start_controls_section(
549 'section_container_style',
550 [
551 'label' => esc_html__('Container', 'king-addons'),
552 'tab' => Controls_Manager::TAB_STYLE,
553 ]
554 );
555
556 $this->add_responsive_control(
557 'container_padding',
558 [
559 'label' => esc_html__('Padding', 'king-addons'),
560 'type' => Controls_Manager::DIMENSIONS,
561 'size_units' => ['px', 'em', '%'],
562 'selectors' => [
563 '{{WRAPPER}} .king-pricing-calculator' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
564 ],
565 'default' => [
566 'top' => '30',
567 'right' => '30',
568 'bottom' => '30',
569 'left' => '30',
570 'unit' => 'px',
571 'isLinked' => true,
572 ],
573 ]
574 );
575
576 $this->add_responsive_control(
577 'container_margin',
578 [
579 'label' => esc_html__('Margin', 'king-addons'),
580 'type' => Controls_Manager::DIMENSIONS,
581 'size_units' => ['px', 'em', '%'],
582 'selectors' => [
583 '{{WRAPPER}} .king-pricing-calculator' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
584 ],
585 ]
586 );
587
588 $this->add_group_control(
589 Group_Control_Background::get_type(),
590 [
591 'name' => 'container_background',
592 'label' => esc_html__('Background', 'king-addons'),
593 'types' => ['classic', 'gradient'],
594 'selector' => '{{WRAPPER}} .king-pricing-calculator',
595 ]
596 );
597
598 $this->add_group_control(
599 Group_Control_Border::get_type(),
600 [
601 'name' => 'container_border',
602 'label' => esc_html__('Border', 'king-addons'),
603 'selector' => '{{WRAPPER}} .king-pricing-calculator',
604 ]
605 );
606
607 $this->add_responsive_control(
608 'container_border_radius',
609 [
610 'label' => esc_html__('Border Radius', 'king-addons'),
611 'type' => Controls_Manager::DIMENSIONS,
612 'size_units' => ['px', '%'],
613 'selectors' => [
614 '{{WRAPPER}} .king-pricing-calculator' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
615 ],
616 ]
617 );
618
619 $this->add_group_control(
620 Group_Control_Box_Shadow::get_type(),
621 [
622 'name' => 'container_box_shadow',
623 'label' => esc_html__('Box Shadow', 'king-addons'),
624 'selector' => '{{WRAPPER}} .king-pricing-calculator',
625 ]
626 );
627
628
629
630
631 $this->end_controls_section();
632
633
634
635
636 // Title & Description Style
637 $this->start_controls_section(
638 'section_title_style',
639 [
640 'label' => esc_html__('Title & Description', 'king-addons'),
641 'tab' => Controls_Manager::TAB_STYLE,
642 ]
643 );
644
645 $this->add_control(
646 'title_color',
647 [
648 'label' => esc_html__('Title Color', 'king-addons'),
649 'type' => Controls_Manager::COLOR,
650 'selectors' => [
651 '{{WRAPPER}} .king-pricing-calculator__title' => 'color: {{VALUE}};',
652 ],
653 ]
654 );
655
656 $this->add_group_control(
657 Group_Control_Typography::get_type(),
658 [
659 'name' => 'title_typography',
660 'selector' => '{{WRAPPER}} .king-pricing-calculator__title',
661 ]
662 );
663
664 $this->add_responsive_control(
665 'title_margin',
666 [
667 'label' => esc_html__('Title Margin', 'king-addons'),
668 'type' => Controls_Manager::DIMENSIONS,
669 'size_units' => ['px', 'em', '%'],
670 'selectors' => [
671 '{{WRAPPER}} .king-pricing-calculator__title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
672 ],
673 ]
674 );
675
676 $this->add_control(
677 'description_color',
678 [
679 'label' => esc_html__('Description Color', 'king-addons'),
680 'type' => Controls_Manager::COLOR,
681 'selectors' => [
682 '{{WRAPPER}} .king-pricing-calculator__description' => 'color: {{VALUE}};',
683 ],
684 ]
685 );
686
687 $this->add_group_control(
688 Group_Control_Typography::get_type(),
689 [
690 'name' => 'description_typography',
691 'selector' => '{{WRAPPER}} .king-pricing-calculator__description',
692 ]
693 );
694
695 $this->add_responsive_control(
696 'description_margin',
697 [
698 'label' => esc_html__('Description Margin', 'king-addons'),
699 'type' => Controls_Manager::DIMENSIONS,
700 'size_units' => ['px', 'em', '%'],
701 'selectors' => [
702 '{{WRAPPER}} .king-pricing-calculator__description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
703 ],
704 ]
705 );
706
707 $this->end_controls_section();
708
709 // Fields Style
710 $this->start_controls_section(
711 'section_fields_style',
712 [
713 'label' => esc_html__('Fields', 'king-addons'),
714 'tab' => Controls_Manager::TAB_STYLE,
715 ]
716 );
717
718 $this->add_responsive_control(
719 'fields_spacing',
720 [
721 'label' => esc_html__('Fields Spacing', 'king-addons'),
722 'type' => Controls_Manager::SLIDER,
723 'size_units' => ['px', 'em'],
724 'range' => [
725 'px' => [
726 'min' => 0,
727 'max' => 100,
728 ],
729 'em' => [
730 'min' => 0,
731 'max' => 10,
732 ],
733 ],
734 'default' => [
735 'unit' => 'px',
736 'size' => 20,
737 ],
738 'selectors' => [
739 '{{WRAPPER}} .king-pricing-calculator__field:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}};',
740 ],
741 ]
742 );
743
744 $this->add_control(
745 'field_label_heading',
746 [
747 'label' => esc_html__('Field Labels', 'king-addons'),
748 'type' => Controls_Manager::HEADING,
749 'separator' => 'before',
750 ]
751 );
752
753 $this->add_control(
754 'field_label_color',
755 [
756 'label' => esc_html__('Label Color', 'king-addons'),
757 'type' => Controls_Manager::COLOR,
758 'selectors' => [
759 '{{WRAPPER}} .king-pricing-calculator__field-label' => 'color: {{VALUE}};',
760 ],
761 ]
762 );
763
764 $this->add_group_control(
765 Group_Control_Typography::get_type(),
766 [
767 'name' => 'field_label_typography',
768 'selector' => '{{WRAPPER}} .king-pricing-calculator__field-label',
769 ]
770 );
771
772 $this->add_responsive_control(
773 'field_label_margin',
774 [
775 'label' => esc_html__('Label Margin', 'king-addons'),
776 'type' => Controls_Manager::DIMENSIONS,
777 'size_units' => ['px', 'em', '%'],
778 'selectors' => [
779 '{{WRAPPER}} .king-pricing-calculator__field-label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
780 ],
781 'default' => [
782 'top' => '0',
783 'right' => '0',
784 'bottom' => '5',
785 'left' => '0',
786 'unit' => 'px',
787 'isLinked' => false,
788 ],
789 ]
790 );
791
792 $this->add_control(
793 'field_description_color',
794 [
795 'label' => esc_html__('Description Color', 'king-addons'),
796 'type' => Controls_Manager::COLOR,
797 'selectors' => [
798 '{{WRAPPER}} .king-pricing-calculator__field-description' => 'color: {{VALUE}};',
799 ],
800 ]
801 );
802
803 $this->add_group_control(
804 Group_Control_Typography::get_type(),
805 [
806 'name' => 'field_description_typography',
807 'selector' => '{{WRAPPER}} .king-pricing-calculator__field-description',
808 ]
809 );
810
811 $this->add_responsive_control(
812 'field_description_margin',
813 [
814 'label' => esc_html__('Description Margin', 'king-addons'),
815 'type' => Controls_Manager::DIMENSIONS,
816 'size_units' => ['px', 'em', '%'],
817 'selectors' => [
818 '{{WRAPPER}} .king-pricing-calculator__field-description' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
819 ],
820 ]
821 );
822
823 $this->add_control(
824 'input_fields_heading',
825 [
826 'label' => esc_html__('Input Fields', 'king-addons'),
827 'type' => Controls_Manager::HEADING,
828 'separator' => 'before',
829 ]
830 );
831
832 $this->add_responsive_control(
833 'input_padding',
834 [
835 'label' => esc_html__('Input Padding', 'king-addons'),
836 'type' => Controls_Manager::DIMENSIONS,
837 'size_units' => ['px', 'em', '%'],
838 'selectors' => [
839 '{{WRAPPER}} .king-pricing-calculator__field input[type="number"],
840 {{WRAPPER}} .king-pricing-calculator__field select' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
841 ],
842 ]
843 );
844
845 $this->start_controls_tabs('input_style_tabs');
846
847 $this->start_controls_tab(
848 'input_normal_tab',
849 [
850 'label' => esc_html__('Normal', 'king-addons'),
851 ]
852 );
853
854 $this->add_control(
855 'input_text_color',
856 [
857 'label' => esc_html__('Text Color', 'king-addons'),
858 'type' => Controls_Manager::COLOR,
859 'selectors' => [
860 '{{WRAPPER}} .king-pricing-calculator__field input,
861 {{WRAPPER}} .king-pricing-calculator__field select,
862 {{WRAPPER}} .king-pricing-calculator__field input::placeholder' => 'color: {{VALUE}};',
863 ],
864 ]
865 );
866
867 $this->add_control(
868 'input_background_color',
869 [
870 'label' => esc_html__('Background Color', 'king-addons'),
871 'type' => Controls_Manager::COLOR,
872 'selectors' => [
873 '{{WRAPPER}} .king-pricing-calculator__field input,
874 {{WRAPPER}} .king-pricing-calculator__field select' => 'background-color: {{VALUE}};',
875 ],
876 ]
877 );
878
879 $this->add_group_control(
880 Group_Control_Border::get_type(),
881 [
882 'name' => 'input_border',
883 'label' => esc_html__('Border', 'king-addons'),
884 'selector' => '{{WRAPPER}} .king-pricing-calculator__field input,
885 {{WRAPPER}} .king-pricing-calculator__field select',
886 ]
887 );
888
889 $this->add_responsive_control(
890 'input_border_radius',
891 [
892 'label' => esc_html__('Border Radius', 'king-addons'),
893 'type' => Controls_Manager::DIMENSIONS,
894 'size_units' => ['px', '%'],
895 'selectors' => [
896 '{{WRAPPER}} .king-pricing-calculator__field input,
897 {{WRAPPER}} .king-pricing-calculator__field select' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
898 ],
899 ]
900 );
901
902 $this->add_group_control(
903 Group_Control_Box_Shadow::get_type(),
904 [
905 'name' => 'input_box_shadow',
906 'selector' => '{{WRAPPER}} .king-pricing-calculator__field input,
907 {{WRAPPER}} .king-pricing-calculator__field select',
908 ]
909 );
910
911 $this->end_controls_tab();
912
913 $this->start_controls_tab(
914 'input_focus_tab',
915 [
916 'label' => esc_html__('Focus', 'king-addons'),
917 ]
918 );
919
920 $this->add_control(
921 'input_focus_text_color',
922 [
923 'label' => esc_html__('Text Color', 'king-addons'),
924 'type' => Controls_Manager::COLOR,
925 'selectors' => [
926 '{{WRAPPER}} .king-pricing-calculator__field input:focus,
927 {{WRAPPER}} .king-pricing-calculator__field select:focus' => 'color: {{VALUE}};',
928 ],
929 ]
930 );
931
932 $this->add_control(
933 'input_focus_background_color',
934 [
935 'label' => esc_html__('Background Color', 'king-addons'),
936 'type' => Controls_Manager::COLOR,
937 'selectors' => [
938 '{{WRAPPER}} .king-pricing-calculator__field input:focus,
939 {{WRAPPER}} .king-pricing-calculator__field select:focus' => 'background-color: {{VALUE}};',
940 ],
941 ]
942 );
943
944 $this->add_control(
945 'input_focus_border_color',
946 [
947 'label' => esc_html__('Border Color', 'king-addons'),
948 'type' => Controls_Manager::COLOR,
949 'selectors' => [
950 '{{WRAPPER}} .king-pricing-calculator__field input:focus,
951 {{WRAPPER}} .king-pricing-calculator__field select:focus' => 'border-color: {{VALUE}};',
952 ],
953 ]
954 );
955
956 $this->add_group_control(
957 Group_Control_Box_Shadow::get_type(),
958 [
959 'name' => 'input_focus_box_shadow',
960 'selector' => '{{WRAPPER}} .king-pricing-calculator__field input:focus,
961 {{WRAPPER}} .king-pricing-calculator__field select:focus',
962 ]
963 );
964
965 $this->end_controls_tab();
966
967 $this->end_controls_tabs();
968
969 $this->add_group_control(
970 Group_Control_Typography::get_type(),
971 [
972 'name' => 'input_typography',
973 'selector' => '{{WRAPPER}} .king-pricing-calculator__field input,
974 {{WRAPPER}} .king-pricing-calculator__field select,
975 {{WRAPPER}} .king-pricing-calculator__field-unit',
976 'separator' => 'before',
977 ]
978 );
979
980 $this->add_control(
981 'range_slider_heading',
982 [
983 'label' => esc_html__('Range Slider', 'king-addons'),
984 'type' => Controls_Manager::HEADING,
985 'separator' => 'before',
986 ]
987 );
988
989 $this->add_control(
990 'range_slider_track_color',
991 [
992 'label' => esc_html__('Track Color', 'king-addons'),
993 'type' => Controls_Manager::COLOR,
994 'selectors' => [
995 '{{WRAPPER}} .king-pricing-calculator__field input[type="range"]' => '--track-color: {{VALUE}};',
996 ],
997 ]
998 );
999
1000 $this->add_control(
1001 'range_slider_progress_color',
1002 [
1003 'label' => esc_html__('Progress Color', 'king-addons'),
1004 'type' => Controls_Manager::COLOR,
1005 'selectors' => [
1006 '{{WRAPPER}} .king-pricing-calculator__field input[type="range"]' => '--progress-color: {{VALUE}};',
1007 ],
1008 ]
1009 );
1010
1011 $this->add_control(
1012 'range_slider_thumb_color',
1013 [
1014 'label' => esc_html__('Thumb Color', 'king-addons'),
1015 'type' => Controls_Manager::COLOR,
1016 'selectors' => [
1017 '{{WRAPPER}} .king-pricing-calculator__field input[type="range"]' => '--thumb-color: {{VALUE}};',
1018 ],
1019 ]
1020 );
1021
1022 $this->add_responsive_control(
1023 'range_slider_track_height',
1024 [
1025 'label' => esc_html__('Track Height', 'king-addons'),
1026 'type' => Controls_Manager::SLIDER,
1027 'size_units' => ['px'],
1028 'range' => [
1029 'px' => [
1030 'min' => 1,
1031 'max' => 20,
1032 ],
1033 ],
1034 'selectors' => [
1035 '{{WRAPPER}} .king-pricing-calculator__field input[type="range"]' => '--track-height: {{SIZE}}{{UNIT}};',
1036 ],
1037 ]
1038 );
1039
1040 $this->add_responsive_control(
1041 'range_slider_thumb_size',
1042 [
1043 'label' => esc_html__('Thumb Size', 'king-addons'),
1044 'type' => Controls_Manager::SLIDER,
1045 'size_units' => ['px'],
1046 'range' => [
1047 'px' => [
1048 'min' => 10,
1049 'max' => 40,
1050 ],
1051 ],
1052 'selectors' => [
1053 '{{WRAPPER}} .king-pricing-calculator__field input[type="range"]' => '--thumb-size: {{SIZE}}{{UNIT}};',
1054 ],
1055 ]
1056 );
1057
1058 $this->end_controls_section();
1059
1060 // Calculate Button Style
1061 $this->start_controls_section(
1062 'section_button_style',
1063 [
1064 'label' => esc_html__('Calculate Button', 'king-addons'),
1065 'tab' => Controls_Manager::TAB_STYLE,
1066 'condition' => [
1067 'enable_calculate_button' => 'yes',
1068 ],
1069 ]
1070 );
1071
1072 $this->add_group_control(
1073 Group_Control_Typography::get_type(),
1074 [
1075 'name' => 'button_typography',
1076 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button',
1077 ]
1078 );
1079
1080 $this->add_responsive_control(
1081 'button_padding',
1082 [
1083 'label' => esc_html__('Padding', 'king-addons'),
1084 'type' => Controls_Manager::DIMENSIONS,
1085 'size_units' => ['px', 'em', '%'],
1086 'selectors' => [
1087 '{{WRAPPER}} .king-pricing-calculator__calculate-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1088 ],
1089 ]
1090 );
1091
1092 $this->add_responsive_control(
1093 'button_margin',
1094 [
1095 'label' => esc_html__('Margin', 'king-addons'),
1096 'type' => Controls_Manager::DIMENSIONS,
1097 'size_units' => ['px', 'em', '%'],
1098 'selectors' => [
1099 '{{WRAPPER}} .king-pricing-calculator__calculate-button-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1100 ],
1101 'default' => [
1102 'top' => '20',
1103 'right' => '0',
1104 'bottom' => '20',
1105 'left' => '0',
1106 'unit' => 'px',
1107 'isLinked' => false,
1108 ],
1109 ]
1110 );
1111
1112 $this->start_controls_tabs('button_style_tabs');
1113
1114 $this->start_controls_tab(
1115 'button_normal_tab',
1116 [
1117 'label' => esc_html__('Normal', 'king-addons'),
1118 ]
1119 );
1120
1121 $this->add_control(
1122 'button_text_color',
1123 [
1124 'label' => esc_html__('Text Color', 'king-addons'),
1125 'type' => Controls_Manager::COLOR,
1126 'selectors' => [
1127 '{{WRAPPER}} .king-pricing-calculator__calculate-button' => 'color: {{VALUE}};',
1128 ],
1129 'default' => '#ffffff',
1130 ]
1131 );
1132
1133 $this->add_group_control(
1134 Group_Control_Background::get_type(),
1135 [
1136 'name' => 'button_background',
1137 'label' => esc_html__('Background', 'king-addons'),
1138 'types' => ['classic', 'gradient'],
1139 'exclude' => ['image'],
1140 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button',
1141 'fields_options' => [
1142 'background' => [
1143 'default' => 'classic',
1144 ],
1145 'color' => [
1146 'default' => '#5cb85c',
1147 ],
1148 ],
1149 ]
1150 );
1151
1152 $this->add_group_control(
1153 Group_Control_Border::get_type(),
1154 [
1155 'name' => 'button_border',
1156 'label' => esc_html__('Border', 'king-addons'),
1157 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button',
1158 ]
1159 );
1160
1161 $this->add_responsive_control(
1162 'button_border_radius',
1163 [
1164 'label' => esc_html__('Border Radius', 'king-addons'),
1165 'type' => Controls_Manager::DIMENSIONS,
1166 'size_units' => ['px', '%'],
1167 'selectors' => [
1168 '{{WRAPPER}} .king-pricing-calculator__calculate-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1169 ],
1170 ]
1171 );
1172
1173 $this->add_group_control(
1174 Group_Control_Box_Shadow::get_type(),
1175 [
1176 'name' => 'button_box_shadow',
1177 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button',
1178 ]
1179 );
1180
1181 $this->end_controls_tab();
1182
1183 $this->start_controls_tab(
1184 'button_hover_tab',
1185 [
1186 'label' => esc_html__('Hover', 'king-addons'),
1187 ]
1188 );
1189
1190 $this->add_control(
1191 'button_hover_text_color',
1192 [
1193 'label' => esc_html__('Text Color', 'king-addons'),
1194 'type' => Controls_Manager::COLOR,
1195 'selectors' => [
1196 '{{WRAPPER}} .king-pricing-calculator__calculate-button:hover' => 'color: {{VALUE}};',
1197 ],
1198 ]
1199 );
1200
1201 $this->add_group_control(
1202 Group_Control_Background::get_type(),
1203 [
1204 'name' => 'button_hover_background',
1205 'label' => esc_html__('Background', 'king-addons'),
1206 'types' => ['classic', 'gradient'],
1207 'exclude' => ['image'],
1208 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button:hover',
1209 'fields_options' => [
1210 'background' => [
1211 'default' => 'classic',
1212 ],
1213 'color' => [
1214 'default' => '#449d44',
1215 ],
1216 ],
1217 ]
1218 );
1219
1220 $this->add_control(
1221 'button_hover_border_color',
1222 [
1223 'label' => esc_html__('Border Color', 'king-addons'),
1224 'type' => Controls_Manager::COLOR,
1225 'selectors' => [
1226 '{{WRAPPER}} .king-pricing-calculator__calculate-button:hover' => 'border-color: {{VALUE}};',
1227 ],
1228 'condition' => [
1229 'button_border_border!' => '',
1230 ],
1231 ]
1232 );
1233
1234 $this->add_group_control(
1235 Group_Control_Box_Shadow::get_type(),
1236 [
1237 'name' => 'button_hover_box_shadow',
1238 'selector' => '{{WRAPPER}} .king-pricing-calculator__calculate-button:hover',
1239 ]
1240 );
1241
1242 $this->add_control(
1243 'button_hover_transition',
1244 [
1245 'label' => esc_html__('Transition Duration', 'king-addons'),
1246 'type' => Controls_Manager::SLIDER,
1247 'default' => [
1248 'size' => 0.3,
1249 ],
1250 'range' => [
1251 'px' => [
1252 'max' => 3,
1253 'step' => 0.1,
1254 ],
1255 ],
1256 'selectors' => [
1257 '{{WRAPPER}} .king-pricing-calculator__calculate-button' => 'transition: all {{SIZE}}s ease;',
1258 ],
1259 ]
1260 );
1261
1262 $this->end_controls_tab();
1263
1264 $this->end_controls_tabs();
1265
1266 $this->end_controls_section();
1267
1268 // Summary Style
1269 $this->start_controls_section(
1270 'section_summary_style',
1271 [
1272 'label' => esc_html__('Summary & Results', 'king-addons'),
1273 'tab' => Controls_Manager::TAB_STYLE,
1274 ]
1275 );
1276
1277 $this->add_control(
1278 'summary_title_color',
1279 [
1280 'label' => esc_html__('Summary Title Color', 'king-addons'),
1281 'type' => Controls_Manager::COLOR,
1282 'selectors' => [
1283 '{{WRAPPER}} .king-pricing-calculator__summary-title' => 'color: {{VALUE}};',
1284 ],
1285 'condition' => [
1286 'show_summary' => 'yes',
1287 ],
1288 ]
1289 );
1290
1291 $this->add_group_control(
1292 Group_Control_Typography::get_type(),
1293 [
1294 'name' => 'summary_title_typography',
1295 'selector' => '{{WRAPPER}} .king-pricing-calculator__summary-title',
1296 'condition' => [
1297 'show_summary' => 'yes',
1298 ],
1299 ]
1300 );
1301
1302 $this->add_responsive_control(
1303 'summary_title_margin',
1304 [
1305 'label' => esc_html__('Summary Title Margin', 'king-addons'),
1306 'type' => Controls_Manager::DIMENSIONS,
1307 'size_units' => ['px', 'em', '%'],
1308 'selectors' => [
1309 '{{WRAPPER}} .king-pricing-calculator__summary-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1310 ],
1311 'condition' => [
1312 'show_summary' => 'yes',
1313 ],
1314 ]
1315 );
1316
1317 $this->add_control(
1318 'summary_container_heading',
1319 [
1320 'label' => esc_html__('Summary Container', 'king-addons'),
1321 'type' => Controls_Manager::HEADING,
1322 'separator' => 'before',
1323 'condition' => [
1324 'show_summary' => 'yes',
1325 ],
1326 ]
1327 );
1328
1329 $this->add_group_control(
1330 Group_Control_Background::get_type(),
1331 [
1332 'name' => 'summary_background',
1333 'label' => esc_html__('Background', 'king-addons'),
1334 'types' => ['classic', 'gradient'],
1335 'selector' => '{{WRAPPER}} .king-pricing-calculator__summary',
1336 'condition' => [
1337 'show_summary' => 'yes',
1338 ],
1339 ]
1340 );
1341
1342 $this->add_group_control(
1343 Group_Control_Border::get_type(),
1344 [
1345 'name' => 'summary_border',
1346 'label' => esc_html__('Border', 'king-addons'),
1347 'selector' => '{{WRAPPER}} .king-pricing-calculator__summary',
1348 'condition' => [
1349 'show_summary' => 'yes',
1350 ],
1351 ]
1352 );
1353
1354 $this->add_responsive_control(
1355 'summary_border_radius',
1356 [
1357 'label' => esc_html__('Border Radius', 'king-addons'),
1358 'type' => Controls_Manager::DIMENSIONS,
1359 'size_units' => ['px', '%'],
1360 'selectors' => [
1361 '{{WRAPPER}} .king-pricing-calculator__summary' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1362 ],
1363 'condition' => [
1364 'show_summary' => 'yes',
1365 ],
1366 ]
1367 );
1368
1369 $this->add_responsive_control(
1370 'summary_padding',
1371 [
1372 'label' => esc_html__('Padding', 'king-addons'),
1373 'type' => Controls_Manager::DIMENSIONS,
1374 'size_units' => ['px', 'em', '%'],
1375 'selectors' => [
1376 '{{WRAPPER}} .king-pricing-calculator__summary' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1377 ],
1378 'condition' => [
1379 'show_summary' => 'yes',
1380 ],
1381 'default' => [
1382 'top' => '15',
1383 'right' => '15',
1384 'bottom' => '15',
1385 'left' => '15',
1386 'unit' => 'px',
1387 'isLinked' => true,
1388 ],
1389 ]
1390 );
1391
1392 $this->add_responsive_control(
1393 'summary_margin',
1394 [
1395 'label' => esc_html__('Margin', 'king-addons'),
1396 'type' => Controls_Manager::DIMENSIONS,
1397 'size_units' => ['px', 'em', '%'],
1398 'selectors' => [
1399 '{{WRAPPER}} .king-pricing-calculator__summary' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1400 ],
1401 'condition' => [
1402 'show_summary' => 'yes',
1403 ],
1404 'default' => [
1405 'top' => '20',
1406 'right' => '0',
1407 'bottom' => '0',
1408 'left' => '0',
1409 'unit' => 'px',
1410 'isLinked' => false,
1411 ],
1412 ]
1413 );
1414
1415 $this->add_control(
1416 'summary_item_heading',
1417 [
1418 'label' => esc_html__('Summary Items', 'king-addons'),
1419 'type' => Controls_Manager::HEADING,
1420 'separator' => 'before',
1421 'condition' => [
1422 'show_summary' => 'yes',
1423 ],
1424 ]
1425 );
1426
1427 $this->add_control(
1428 'summary_item_color',
1429 [
1430 'label' => esc_html__('Item Text Color', 'king-addons'),
1431 'type' => Controls_Manager::COLOR,
1432 'selectors' => [
1433 '{{WRAPPER}} .king-pricing-calculator__summary-item' => 'color: {{VALUE}};',
1434 ],
1435 'condition' => [
1436 'show_summary' => 'yes',
1437 ],
1438 ]
1439 );
1440
1441 $this->add_group_control(
1442 Group_Control_Typography::get_type(),
1443 [
1444 'name' => 'summary_item_typography',
1445 'selector' => '{{WRAPPER}} .king-pricing-calculator__summary-item',
1446 'condition' => [
1447 'show_summary' => 'yes',
1448 ],
1449 ]
1450 );
1451
1452 $this->add_responsive_control(
1453 'summary_item_spacing',
1454 [
1455 'label' => esc_html__('Item Spacing', 'king-addons'),
1456 'type' => Controls_Manager::SLIDER,
1457 'size_units' => ['px', 'em'],
1458 'range' => [
1459 'px' => [
1460 'min' => 0,
1461 'max' => 50,
1462 ],
1463 'em' => [
1464 'min' => 0,
1465 'max' => 5,
1466 ],
1467 ],
1468 'selectors' => [
1469 '{{WRAPPER}} .king-pricing-calculator__summary-item:not(:last-child)' => 'margin-bottom: {{SIZE}}{{UNIT}};',
1470 ],
1471 'condition' => [
1472 'show_summary' => 'yes',
1473 ],
1474 ]
1475 );
1476
1477 $this->add_control(
1478 'total_heading',
1479 [
1480 'label' => esc_html__('Total Price', 'king-addons'),
1481 'type' => Controls_Manager::HEADING,
1482 'separator' => 'before',
1483 ]
1484 );
1485
1486 $this->add_control(
1487 'total_label_color',
1488 [
1489 'label' => esc_html__('Total Label Color', 'king-addons'),
1490 'type' => Controls_Manager::COLOR,
1491 'selectors' => [
1492 '{{WRAPPER}} .king-pricing-calculator__total-label' => 'color: {{VALUE}};',
1493 ],
1494 ]
1495 );
1496
1497 $this->add_group_control(
1498 Group_Control_Typography::get_type(),
1499 [
1500 'name' => 'total_label_typography',
1501 'selector' => '{{WRAPPER}} .king-pricing-calculator__total-label',
1502 ]
1503 );
1504
1505 $this->add_control(
1506 'total_price_color',
1507 [
1508 'label' => esc_html__('Total Price Color', 'king-addons'),
1509 'type' => Controls_Manager::COLOR,
1510 'selectors' => [
1511 '{{WRAPPER}} .king-pricing-calculator__total-price' => 'color: {{VALUE}};',
1512 ],
1513 ]
1514 );
1515
1516 $this->add_group_control(
1517 Group_Control_Typography::get_type(),
1518 [
1519 'name' => 'total_price_typography',
1520 'selector' => '{{WRAPPER}} .king-pricing-calculator__total-price',
1521 ]
1522 );
1523
1524 $this->add_group_control(
1525 Group_Control_Background::get_type(),
1526 [
1527 'name' => 'total_background',
1528 'label' => esc_html__('Background', 'king-addons'),
1529 'types' => ['classic', 'gradient'],
1530 'selector' => '{{WRAPPER}} .king-pricing-calculator__total',
1531 ]
1532 );
1533
1534 $this->add_group_control(
1535 Group_Control_Border::get_type(),
1536 [
1537 'name' => 'total_border',
1538 'label' => esc_html__('Border', 'king-addons'),
1539 'selector' => '{{WRAPPER}} .king-pricing-calculator__total',
1540 ]
1541 );
1542
1543 $this->add_responsive_control(
1544 'total_border_radius',
1545 [
1546 'label' => esc_html__('Border Radius', 'king-addons'),
1547 'type' => Controls_Manager::DIMENSIONS,
1548 'size_units' => ['px', '%'],
1549 'selectors' => [
1550 '{{WRAPPER}} .king-pricing-calculator__total' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1551 ],
1552 ]
1553 );
1554
1555 $this->add_responsive_control(
1556 'total_padding',
1557 [
1558 'label' => esc_html__('Padding', 'king-addons'),
1559 'type' => Controls_Manager::DIMENSIONS,
1560 'size_units' => ['px', 'em', '%'],
1561 'selectors' => [
1562 '{{WRAPPER}} .king-pricing-calculator__total' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1563 ],
1564 'default' => [
1565 'top' => '15',
1566 'right' => '15',
1567 'bottom' => '15',
1568 'left' => '15',
1569 'unit' => 'px',
1570 'isLinked' => true,
1571 ],
1572 ]
1573 );
1574
1575 $this->add_responsive_control(
1576 'total_margin',
1577 [
1578 'label' => esc_html__('Margin', 'king-addons'),
1579 'type' => Controls_Manager::DIMENSIONS,
1580 'size_units' => ['px', 'em', '%'],
1581 'selectors' => [
1582 '{{WRAPPER}} .king-pricing-calculator__total' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
1583 ],
1584 'default' => [
1585 'top' => '20',
1586 'right' => '0',
1587 'bottom' => '0',
1588 'left' => '0',
1589 'unit' => 'px',
1590 'isLinked' => false,
1591 ],
1592 ]
1593 );
1594
1595 $this->end_controls_section();
1596 }
1597
1598 /**
1599 * Format a number with proper separators
1600 *
1601 * @param float $number The number to format
1602 * @param array $settings Widget settings
1603 * @return string Formatted number
1604 */
1605 protected function format_number($number, $settings)
1606 {
1607 $decimal_places = intval($settings['decimal_places']);
1608 // Sanitize separators to prevent XSS
1609 $thousand_separator = wp_strip_all_tags($settings['thousand_separator']);
1610 $decimal_separator = wp_strip_all_tags($settings['decimal_separator']);
1611
1612 return number_format($number, $decimal_places, $decimal_separator, $thousand_separator);
1613 }
1614
1615 /**
1616 * Render field based on its type
1617 *
1618 * @param array $field Field settings
1619 * @param string $field_id Unique field ID
1620 * @return string HTML markup for the field
1621 */
1622 protected function render_field($field, $field_id)
1623 {
1624 $html = '<div class="king-pricing-calculator__field" data-field-id="' . esc_attr($field_id) . '" data-field-type="' . esc_attr($field['field_type']) . '" data-price-type="' . esc_attr($field['field_price_type']) . '"';
1625
1626 switch ($field['field_type']) {
1627 case 'number':
1628 case 'range':
1629 $html .= ' data-price="' . esc_attr($field['field_price']) . '"';
1630 break;
1631
1632 case 'checkbox':
1633 case 'switch':
1634 $html .= ' data-price="' . esc_attr($field['checkbox_value']) . '"';
1635 break;
1636 }
1637
1638 $html .= '>';
1639
1640 // Field Label
1641 if (!empty($field['field_label'])) {
1642 $html .= '<label class="king-pricing-calculator__field-label" for="' . esc_attr($field_id) . '">' . esc_html($field['field_label']) . '</label>';
1643 }
1644
1645 // Field Description
1646 if (!empty($field['field_description'])) {
1647 $html .= '<div class="king-pricing-calculator__field-description" id="' . esc_attr($field_id) . '-desc">' . esc_html($field['field_description']) . '</div>';
1648 }
1649
1650 // Field Input
1651 $html .= '<div class="king-pricing-calculator__field-input">';
1652
1653 switch ($field['field_type']) {
1654 case 'number':
1655 $html .= $this->render_number_field($field, $field_id);
1656 break;
1657
1658 case 'range':
1659 $html .= $this->render_range_field($field, $field_id);
1660 break;
1661
1662 case 'select':
1663 $html .= $this->render_select_field($field, $field_id);
1664 break;
1665
1666 case 'radio':
1667 $html .= $this->render_radio_field($field, $field_id);
1668 break;
1669
1670 case 'checkbox':
1671 $html .= $this->render_checkbox_field($field, $field_id);
1672 break;
1673
1674 case 'switch':
1675 $html .= $this->render_switch_field($field, $field_id);
1676 break;
1677 }
1678
1679 $html .= '</div></div>';
1680
1681 return $html;
1682 }
1683
1684 /**
1685 * Render a number input field
1686 *
1687 * @param array $field Field settings
1688 * @param string $field_id Unique field ID
1689 * @return string HTML markup for number field
1690 */
1691 protected function render_number_field($field, $field_id)
1692 {
1693 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1694 $aria_desc = !empty($desc_id) ? ' aria-describedby="' . esc_attr($desc_id) . '"' : '';
1695
1696 $html = '<div class="king-pricing-calculator__number-field">';
1697 $html .= '<input type="number" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_id) . '"';
1698 $html .= ' min="' . esc_attr($field['field_min']) . '" max="' . esc_attr($field['field_max']) . '" step="' . esc_attr($field['field_step']) . '"';
1699 $html .= ' value="' . esc_attr($field['field_default']) . '"';
1700 $html .= ' class="king-pricing-calculator__input"' . $aria_desc . '>';
1701
1702 if (!empty($field['field_unit'])) {
1703 $html .= '<span class="king-pricing-calculator__field-unit" aria-hidden="true">' . esc_html($field['field_unit']) . '</span>';
1704 }
1705
1706 $html .= '</div>';
1707
1708 return $html;
1709 }
1710
1711 /**
1712 * Render a range slider field
1713 *
1714 * @param array $field Field settings
1715 * @param string $field_id Unique field ID
1716 * @return string HTML markup for range field
1717 */
1718 protected function render_range_field($field, $field_id)
1719 {
1720 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1721 $aria_desc = !empty($desc_id) ? ' aria-describedby="' . esc_attr($desc_id) . '"' : '';
1722 $value_id = $field_id . '-value';
1723
1724 $html = '<div class="king-pricing-calculator__range-field">';
1725 $html .= '<input type="range" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_id) . '"';
1726 $html .= ' min="' . esc_attr($field['field_min']) . '" max="' . esc_attr($field['field_max']) . '" step="' . esc_attr($field['field_step']) . '"';
1727 $html .= ' value="' . esc_attr($field['field_default']) . '"';
1728 $html .= ' class="king-pricing-calculator__range"' . $aria_desc . ' aria-valuetext="' . esc_attr($field['field_default']) . (!empty($field['field_unit']) ? ' ' . $field['field_unit'] : '') . '">';
1729
1730 $html .= '<div class="king-pricing-calculator__range-value-display" aria-hidden="true">';
1731 $html .= '<span class="king-pricing-calculator__range-value" id="' . esc_attr($value_id) . '">' . esc_html($field['field_default']) . '</span>';
1732
1733 if (!empty($field['field_unit'])) {
1734 $html .= ' <span class="king-pricing-calculator__field-unit">' . esc_html($field['field_unit']) . '</span>';
1735 }
1736
1737 $html .= '</div>';
1738 $html .= '</div>';
1739
1740 return $html;
1741 }
1742
1743 /**
1744 * Render a select dropdown field
1745 *
1746 * @param array $field Field settings
1747 * @param string $field_id Unique field ID
1748 * @return string HTML markup for select field
1749 */
1750 protected function render_select_field($field, $field_id)
1751 {
1752 $options = $this->parse_options($field['field_options']);
1753 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1754 $aria_desc = !empty($desc_id) ? ' aria-describedby="' . esc_attr($desc_id) . '"' : '';
1755
1756 $html = '<select id="' . esc_attr($field_id) . '" name="' . esc_attr($field_id) . '" class="king-pricing-calculator__select"' . $aria_desc . '>';
1757
1758 foreach ($options as $option) {
1759 $html .= '<option value="' . esc_attr($option['value']) . '" data-price="' . esc_attr($option['price']) . '">' . esc_html($option['label']) . '</option>';
1760 }
1761
1762 $html .= '</select>';
1763
1764 return $html;
1765 }
1766
1767 /**
1768 * Render radio button options
1769 *
1770 * @param array $field Field settings
1771 * @param string $field_id Unique field ID
1772 * @return string HTML markup for radio buttons
1773 */
1774 protected function render_radio_field($field, $field_id)
1775 {
1776 $options = $this->parse_options($field['field_options']);
1777 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1778 $fieldset_id = $field_id . '-group';
1779
1780 $html = '<fieldset id="' . esc_attr($fieldset_id) . '" class="king-pricing-calculator__radio-group">';
1781 if (!empty($desc_id)) {
1782 $html .= '<div aria-describedby="' . esc_attr($desc_id) . '" hidden></div>';
1783 }
1784
1785 foreach ($options as $index => $option) {
1786 $option_id = $field_id . '_' . $index;
1787
1788 $html .= '<div class="king-pricing-calculator__radio-option">';
1789 $html .= '<input type="radio" id="' . esc_attr($option_id) . '" name="' . esc_attr($field_id) . '"';
1790 $html .= ' value="' . esc_attr($option['value']) . '" data-price="' . esc_attr($option['price']) . '"';
1791
1792 if ($index === 0) {
1793 $html .= ' checked';
1794 }
1795
1796 $html .= ' class="king-pricing-calculator__radio">';
1797 $html .= '<label for="' . esc_attr($option_id) . '">' . esc_html($option['label']) . '</label>';
1798 $html .= '</div>';
1799 }
1800
1801 $html .= '</fieldset>';
1802
1803 return $html;
1804 }
1805
1806 /**
1807 * Render a checkbox field
1808 *
1809 * @param array $field Field settings
1810 * @param string $field_id Unique field ID
1811 * @return string HTML markup for checkbox
1812 */
1813 protected function render_checkbox_field($field, $field_id)
1814 {
1815 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1816 $aria_desc = !empty($desc_id) ? ' aria-describedby="' . esc_attr($desc_id) . '"' : '';
1817
1818 $html = '<div class="king-pricing-calculator__checkbox-field">';
1819 $html .= '<input type="checkbox" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_id) . '"';
1820 $html .= ' class="king-pricing-calculator__checkbox"' . $aria_desc . '>';
1821 $html .= '</div>';
1822
1823 return $html;
1824 }
1825
1826 /**
1827 * Render a toggle switch field
1828 *
1829 * @param array $field Field settings
1830 * @param string $field_id Unique field ID
1831 * @return string HTML markup for switch
1832 */
1833 protected function render_switch_field($field, $field_id)
1834 {
1835 $desc_id = !empty($field['field_description']) ? $field_id . '-desc' : '';
1836 $aria_desc = !empty($desc_id) ? ' aria-describedby="' . esc_attr($desc_id) . '"' : '';
1837
1838 $html = '<label class="king-pricing-calculator__switch">';
1839 $html .= '<input type="checkbox" id="' . esc_attr($field_id) . '" name="' . esc_attr($field_id) . '"';
1840 $html .= ' class="king-pricing-calculator__switch-input"' . $aria_desc . ' role="switch">';
1841 $html .= '<span class="king-pricing-calculator__switch-slider" aria-hidden="true"></span>';
1842 $html .= '</label>';
1843
1844 return $html;
1845 }
1846
1847 /**
1848 * Parse options string into structured array
1849 *
1850 * @param string $options_string Options in format "value|label|price"
1851 * @return array Structured options array
1852 */
1853 protected function parse_options($options_string)
1854 {
1855 $options = [];
1856 $lines = explode("\n", $options_string);
1857
1858 foreach ($lines as $line) {
1859 $parts = explode('|', trim($line));
1860
1861 if (count($parts) >= 3) {
1862 $options[] = [
1863 'value' => $parts[0],
1864 'label' => $parts[1],
1865 'price' => floatval($parts[2]),
1866 ];
1867 }
1868 }
1869
1870 return $options;
1871 }
1872
1873 /**
1874 * Render widget output on the frontend
1875 */
1876 protected function render()
1877 {
1878 $settings = $this->get_settings_for_display();
1879 $id_int = substr($this->get_id_int(), 0, 3);
1880
1881 $calculator_id = 'king-pricing-calculator-' . $this->get_id();
1882 $calculator_classes = ['king-pricing-calculator'];
1883
1884 if ($settings['live_calculation'] === 'yes') {
1885 $calculator_classes[] = 'king-pricing-calculator--live';
1886 }
1887
1888 if (!king_addons_freemius()->can_use_premium_code__premium_only()) {
1889 $this->add_render_attribute('calculator', [
1890 'id' => $calculator_id,
1891 'class' => $calculator_classes,
1892 'data-base-price' => floatval($settings['base_price']),
1893 'data-decimal-places' => intval($settings['decimal_places']),
1894 'data-thousand-separator' => esc_attr($settings['thousand_separator']),
1895 'data-decimal-separator' => esc_attr($settings['decimal_separator']),
1896 'data-price-prefix' => esc_attr($settings['price_prefix']),
1897 'data-price-suffix' => esc_attr($settings['price_suffix']),
1898 ]);}
1899
1900 ?>
1901 <div <?php $this->print_render_attribute_string('calculator'); ?>>
1902 <?php if (!empty($settings['calculator_title'])) : ?>
1903 <h2 class="king-pricing-calculator__title"><?php echo esc_html($settings['calculator_title']); ?></h2>
1904 <?php endif; ?>
1905
1906 <?php if (!empty($settings['calculator_description'])) : ?>
1907 <div class="king-pricing-calculator__description"><?php echo esc_html($settings['calculator_description']); ?></div>
1908 <?php endif; ?>
1909
1910 <div class="king-pricing-calculator__fields">
1911 <?php
1912 if (!empty($settings['calculator_fields'])) {
1913 foreach ($settings['calculator_fields'] as $index => $field) {
1914 // Use custom field ID if provided, otherwise generate an automatic one
1915 if (!empty($field['field_id'])) {
1916 $field_id = 'king-calc-' . sanitize_key($field['field_id']);
1917 } else {
1918 $field_id = 'king-calculator-field-' . $id_int . '-' . $index;
1919 }
1920 echo $this->render_field($field, $field_id);
1921 }
1922 }
1923 ?>
1924 </div>
1925
1926 <?php if ($settings['enable_calculate_button'] === 'yes' && $settings['live_calculation'] !== 'yes') : ?>
1927 <div class="king-pricing-calculator__calculate-button-wrapper">
1928 <button type="button" class="king-pricing-calculator__calculate-button">
1929 <?php echo esc_html($settings['calculate_button_text']); ?>
1930 </button>
1931 </div>
1932 <?php endif; ?>
1933
1934 <?php if ($settings['show_summary'] === 'yes') : ?>
1935 <div class="king-pricing-calculator__summary">
1936 <?php if (!empty($settings['summary_title'])) : ?>
1937 <h3 class="king-pricing-calculator__summary-title"><?php echo esc_html($settings['summary_title']); ?></h3>
1938 <?php endif; ?>
1939
1940 <div class="king-pricing-calculator__summary-items"></div>
1941 </div>
1942 <?php endif; ?>
1943
1944 <div class="king-pricing-calculator__total">
1945 <div class="king-pricing-calculator__total-content">
1946 <span class="king-pricing-calculator__total-label"><?php echo esc_html($settings['total_text']); ?></span>
1947 <span class="king-pricing-calculator__total-price">
1948 <?php echo esc_html($settings['price_prefix'] . $this->format_number($settings['base_price'], $settings) . $settings['price_suffix']); ?>
1949 </span>
1950 </div>
1951 </div>
1952
1953 <?php if (!king_addons_freemius()->can_use_premium_code__premium_only()) : ?>
1954 <div class="king-pricing-calculator__pro-features">
1955 <a href="https://kingaddons.com/pricing/?utm_source=kng-module-pricing-calculator-widget-upgrade-pro&utm_medium=plugin&utm_campaign=kng" target="_blank">
1956 <?php echo esc_html__('Notice for Editors: Upgrade to Pro for advanced pricing formulas, conditional logic & more features', 'king-addons'); ?>
1957 </a>
1958 </div>
1959 <?php endif; ?>
1960 </div>
1961 <?php
1962 }
1963 }