PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.65
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.65
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 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Woo_Shortcode_Checkout / Woo_Shortcode_Checkout.php

Woo_Shortcode_Checkout.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.65, at includes/widgets/Woo_Shortcode_Checkout/Woo_Shortcode_Checkout.php

694 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Shortcode Checkout widget.
4 * Renders the standard WooCommerce [woocommerce_checkout] shortcode.
5 *
6 * @package King_Addons
7 */
8
9 namespace King_Addons;
10
11 use Elementor\Controls_Manager;
12 use Elementor\Group_Control_Typography;
13 use Elementor\Group_Control_Border;
14 use Elementor\Group_Control_Box_Shadow;
15 use Elementor\Widget_Base;
16
17 if (!defined('ABSPATH')) {
18 exit;
19 }
20
21 /**
22 * Displays WooCommerce checkout using the standard shortcode.
23 */
24 class Woo_Shortcode_Checkout extends Widget_Base
25 {
26 /**
27 * Get widget name.
28 *
29 * @return string
30 */
31 public function get_name(): string
32 {
33 return 'woo_shortcode_checkout';
34 }
35
36 /**
37 * Get widget title.
38 *
39 * @return string
40 */
41 public function get_title(): string
42 {
43 return esc_html__('WC Checkout', 'king-addons');
44 }
45
46 /**
47 * Get widget icon.
48 *
49 * @return string
50 */
51 public function get_icon(): string
52 {
53 return 'eicon-checkout';
54 }
55
56 /**
57 * Get widget categories.
58 *
59 * @return array<int,string>
60 */
61 public function get_categories(): array
62 {
63 return ['king-addons-woo-builder'];
64 }
65
66 /**
67 * Get widget keywords.
68 *
69 * @return array<int,string>
70 */
71 public function get_keywords(): array
72 {
73 return ['woocommerce', 'checkout', 'shortcode', 'payment', 'order'];
74 }
75
76 /**
77 * Register controls.
78 *
79 * @return void
80 */
81 public function get_custom_help_url()
82 {
83 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
84 }
85
86 protected function register_controls(): void
87 {
88 $this->start_controls_section(
89 'section_info',
90 [
91 'label' => esc_html__('Info', 'king-addons'),
92 'tab' => Controls_Manager::TAB_CONTENT,
93 ]
94 );
95
96 $this->add_control(
97 'info_notice',
98 [
99 'type' => Controls_Manager::RAW_HTML,
100 'raw' => sprintf(
101 '<div style="padding: 15px; background: #f0f6fc; border-left: 4px solid #2271b1; border-radius: 4px; color: #1d4ed8;">
102 <strong>%s</strong><br><br>%s
103 </div>',
104 esc_html__('WooCommerce Checkout Shortcode', 'king-addons'),
105 esc_html__('This widget renders the standard WooCommerce checkout page using the [woocommerce_checkout] shortcode. It displays the full checkout form with billing, shipping, payment methods, and order review.', 'king-addons')
106 ),
107 'content_classes' => 'elementor-panel-alert',
108 ]
109 );
110
111 $this->end_controls_section();
112
113 // =============================================
114 // STYLE TAB
115 // =============================================
116
117 // Section Titles Style
118 $this->start_controls_section(
119 'section_style_headings',
120 [
121 'label' => esc_html__('Section Headings', 'king-addons'),
122 'tab' => Controls_Manager::TAB_STYLE,
123 ]
124 );
125
126 $this->add_control(
127 'heading_color',
128 [
129 'label' => esc_html__('Color', 'king-addons'),
130 'type' => Controls_Manager::COLOR,
131 'selectors' => [
132 '{{WRAPPER}} .woocommerce-checkout h3' => 'color: {{VALUE}};',
133 '{{WRAPPER}} #order_review_heading' => 'color: {{VALUE}};',
134 ],
135 ]
136 );
137
138 $this->add_group_control(
139 Group_Control_Typography::get_type(),
140 [
141 'name' => 'heading_typography',
142 'selector' => '{{WRAPPER}} .woocommerce-checkout h3, {{WRAPPER}} #order_review_heading',
143 ]
144 );
145
146 $this->add_responsive_control(
147 'heading_spacing',
148 [
149 'label' => esc_html__('Spacing', 'king-addons'),
150 'type' => Controls_Manager::SLIDER,
151 'size_units' => ['px', 'em'],
152 'selectors' => [
153 '{{WRAPPER}} .woocommerce-checkout h3' => 'margin-bottom: {{SIZE}}{{UNIT}};',
154 '{{WRAPPER}} #order_review_heading' => 'margin-bottom: {{SIZE}}{{UNIT}};',
155 ],
156 ]
157 );
158
159 $this->end_controls_section();
160
161 // Form Labels Style
162 $this->start_controls_section(
163 'section_style_labels',
164 [
165 'label' => esc_html__('Form Labels', 'king-addons'),
166 'tab' => Controls_Manager::TAB_STYLE,
167 ]
168 );
169
170 $this->add_control(
171 'label_color',
172 [
173 'label' => esc_html__('Color', 'king-addons'),
174 'type' => Controls_Manager::COLOR,
175 'selectors' => [
176 '{{WRAPPER}} .woocommerce-checkout form label' => 'color: {{VALUE}};',
177 ],
178 ]
179 );
180
181 $this->add_group_control(
182 Group_Control_Typography::get_type(),
183 [
184 'name' => 'label_typography',
185 'selector' => '{{WRAPPER}} .woocommerce-checkout form label',
186 ]
187 );
188
189 $this->add_control(
190 'required_color',
191 [
192 'label' => esc_html__('Required Asterisk Color', 'king-addons'),
193 'type' => Controls_Manager::COLOR,
194 'selectors' => [
195 '{{WRAPPER}} .woocommerce-checkout form label .required' => 'color: {{VALUE}};',
196 ],
197 ]
198 );
199
200 $this->end_controls_section();
201
202 // Form Fields Style
203 $this->start_controls_section(
204 'section_style_fields',
205 [
206 'label' => esc_html__('Form Fields', 'king-addons'),
207 'tab' => Controls_Manager::TAB_STYLE,
208 ]
209 );
210
211 $this->add_control(
212 'field_bg_color',
213 [
214 'label' => esc_html__('Background Color', 'king-addons'),
215 'type' => Controls_Manager::COLOR,
216 'selectors' => [
217 '{{WRAPPER}} .woocommerce-checkout input.input-text' => 'background-color: {{VALUE}};',
218 '{{WRAPPER}} .woocommerce-checkout textarea' => 'background-color: {{VALUE}};',
219 '{{WRAPPER}} .woocommerce-checkout select' => 'background-color: {{VALUE}};',
220 ],
221 ]
222 );
223
224 $this->add_control(
225 'field_text_color',
226 [
227 'label' => esc_html__('Text Color', 'king-addons'),
228 'type' => Controls_Manager::COLOR,
229 'selectors' => [
230 '{{WRAPPER}} .woocommerce-checkout input.input-text' => 'color: {{VALUE}};',
231 '{{WRAPPER}} .woocommerce-checkout textarea' => 'color: {{VALUE}};',
232 '{{WRAPPER}} .woocommerce-checkout select' => 'color: {{VALUE}};',
233 ],
234 ]
235 );
236
237 $this->add_control(
238 'field_placeholder_color',
239 [
240 'label' => esc_html__('Placeholder Color', 'king-addons'),
241 'type' => Controls_Manager::COLOR,
242 'selectors' => [
243 '{{WRAPPER}} .woocommerce-checkout input.input-text::placeholder' => 'color: {{VALUE}};',
244 '{{WRAPPER}} .woocommerce-checkout textarea::placeholder' => 'color: {{VALUE}};',
245 ],
246 ]
247 );
248
249 $this->add_group_control(
250 Group_Control_Border::get_type(),
251 [
252 'name' => 'field_border',
253 'selector' => '{{WRAPPER}} .woocommerce-checkout input.input-text, {{WRAPPER}} .woocommerce-checkout textarea, {{WRAPPER}} .woocommerce-checkout select',
254 ]
255 );
256
257 $this->add_responsive_control(
258 'field_border_radius',
259 [
260 'label' => esc_html__('Border Radius', 'king-addons'),
261 'type' => Controls_Manager::DIMENSIONS,
262 'size_units' => ['px', '%'],
263 'selectors' => [
264 '{{WRAPPER}} .woocommerce-checkout input.input-text' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
265 '{{WRAPPER}} .woocommerce-checkout textarea' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
266 '{{WRAPPER}} .woocommerce-checkout select' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
267 ],
268 ]
269 );
270
271 $this->add_responsive_control(
272 'field_padding',
273 [
274 'label' => esc_html__('Padding', 'king-addons'),
275 'type' => Controls_Manager::DIMENSIONS,
276 'size_units' => ['px', 'em'],
277 'selectors' => [
278 '{{WRAPPER}} .woocommerce-checkout input.input-text' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
279 '{{WRAPPER}} .woocommerce-checkout textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
280 '{{WRAPPER}} .woocommerce-checkout select' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
281 ],
282 ]
283 );
284
285 $this->end_controls_section();
286
287 // Order Review Table Style
288 $this->start_controls_section(
289 'section_style_order_review',
290 [
291 'label' => esc_html__('Order Review Table', 'king-addons'),
292 'tab' => Controls_Manager::TAB_STYLE,
293 ]
294 );
295
296 $this->add_control(
297 'order_review_bg_color',
298 [
299 'label' => esc_html__('Background Color', 'king-addons'),
300 'type' => Controls_Manager::COLOR,
301 'selectors' => [
302 '{{WRAPPER}} #order_review' => 'background-color: {{VALUE}};',
303 ],
304 ]
305 );
306
307 $this->add_responsive_control(
308 'order_review_padding',
309 [
310 'label' => esc_html__('Padding', 'king-addons'),
311 'type' => Controls_Manager::DIMENSIONS,
312 'size_units' => ['px', 'em'],
313 'selectors' => [
314 '{{WRAPPER}} #order_review' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
315 ],
316 ]
317 );
318
319 $this->add_group_control(
320 Group_Control_Border::get_type(),
321 [
322 'name' => 'order_review_border',
323 'selector' => '{{WRAPPER}} #order_review',
324 ]
325 );
326
327 $this->add_responsive_control(
328 'order_review_border_radius',
329 [
330 'label' => esc_html__('Border Radius', 'king-addons'),
331 'type' => Controls_Manager::DIMENSIONS,
332 'size_units' => ['px', '%'],
333 'selectors' => [
334 '{{WRAPPER}} #order_review' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
335 ],
336 ]
337 );
338
339 $this->end_controls_section();
340
341 // Payment Methods Style
342 $this->start_controls_section(
343 'section_style_payment',
344 [
345 'label' => esc_html__('Payment Methods', 'king-addons'),
346 'tab' => Controls_Manager::TAB_STYLE,
347 ]
348 );
349
350 $this->add_control(
351 'payment_bg_color',
352 [
353 'label' => esc_html__('Background Color', 'king-addons'),
354 'type' => Controls_Manager::COLOR,
355 'selectors' => [
356 '{{WRAPPER}} #payment' => 'background-color: {{VALUE}};',
357 ],
358 ]
359 );
360
361 $this->add_control(
362 'payment_label_color',
363 [
364 'label' => esc_html__('Label Color', 'king-addons'),
365 'type' => Controls_Manager::COLOR,
366 'selectors' => [
367 '{{WRAPPER}} #payment .wc_payment_method label' => 'color: {{VALUE}};',
368 ],
369 ]
370 );
371
372 $this->add_group_control(
373 Group_Control_Typography::get_type(),
374 [
375 'name' => 'payment_label_typography',
376 'selector' => '{{WRAPPER}} #payment .wc_payment_method label',
377 ]
378 );
379
380 $this->add_responsive_control(
381 'payment_padding',
382 [
383 'label' => esc_html__('Padding', 'king-addons'),
384 'type' => Controls_Manager::DIMENSIONS,
385 'size_units' => ['px', 'em'],
386 'selectors' => [
387 '{{WRAPPER}} #payment' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
388 ],
389 ]
390 );
391
392 $this->add_responsive_control(
393 'payment_border_radius',
394 [
395 'label' => esc_html__('Border Radius', 'king-addons'),
396 'type' => Controls_Manager::DIMENSIONS,
397 'size_units' => ['px', '%'],
398 'selectors' => [
399 '{{WRAPPER}} #payment' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
400 ],
401 ]
402 );
403
404 $this->add_group_control(
405 Group_Control_Border::get_type(),
406 [
407 'name' => 'payment_border',
408 'selector' => '{{WRAPPER}} #payment',
409 ]
410 );
411
412 $this->end_controls_section();
413
414 // Order Table Style
415 $this->start_controls_section(
416 'section_style_order_table',
417 [
418 'label' => esc_html__('Order Table', 'king-addons'),
419 'tab' => Controls_Manager::TAB_STYLE,
420 ]
421 );
422
423 $this->add_control(
424 'order_table_header_color',
425 [
426 'label' => esc_html__('Header Text Color', 'king-addons'),
427 'type' => Controls_Manager::COLOR,
428 'selectors' => [
429 '{{WRAPPER}} .woocommerce-checkout-review-order-table th' => 'color: {{VALUE}};',
430 ],
431 ]
432 );
433
434 $this->add_control(
435 'order_table_header_bg',
436 [
437 'label' => esc_html__('Header Background', 'king-addons'),
438 'type' => Controls_Manager::COLOR,
439 'selectors' => [
440 '{{WRAPPER}} .woocommerce-checkout-review-order-table th' => 'background-color: {{VALUE}};',
441 ],
442 ]
443 );
444
445 $this->add_control(
446 'order_table_cell_color',
447 [
448 'label' => esc_html__('Cell Text Color', 'king-addons'),
449 'type' => Controls_Manager::COLOR,
450 'selectors' => [
451 '{{WRAPPER}} .woocommerce-checkout-review-order-table td' => 'color: {{VALUE}};',
452 ],
453 ]
454 );
455
456 $this->add_group_control(
457 Group_Control_Border::get_type(),
458 [
459 'name' => 'order_table_border',
460 'selector' => '{{WRAPPER}} .woocommerce-checkout-review-order-table, {{WRAPPER}} .woocommerce-checkout-review-order-table th, {{WRAPPER}} .woocommerce-checkout-review-order-table td',
461 ]
462 );
463
464 $this->add_responsive_control(
465 'order_table_padding',
466 [
467 'label' => esc_html__('Cell Padding', 'king-addons'),
468 'type' => Controls_Manager::DIMENSIONS,
469 'size_units' => ['px', 'em'],
470 'selectors' => [
471 '{{WRAPPER}} .woocommerce-checkout-review-order-table th' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
472 '{{WRAPPER}} .woocommerce-checkout-review-order-table td' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
473 ],
474 ]
475 );
476
477 $this->end_controls_section();
478
479 // Form Rows Style
480 $this->start_controls_section(
481 'section_style_form_rows',
482 [
483 'label' => esc_html__('Form Rows', 'king-addons'),
484 'tab' => Controls_Manager::TAB_STYLE,
485 ]
486 );
487
488 $this->add_responsive_control(
489 'form_row_spacing',
490 [
491 'label' => esc_html__('Row Spacing', 'king-addons'),
492 'type' => Controls_Manager::SLIDER,
493 'size_units' => ['px', 'em'],
494 'range' => [
495 'px' => [
496 'min' => 0,
497 'max' => 50,
498 ],
499 ],
500 'selectors' => [
501 '{{WRAPPER}} .woocommerce-checkout .form-row' => 'margin-bottom: {{SIZE}}{{UNIT}};',
502 ],
503 ]
504 );
505
506 $this->add_responsive_control(
507 'form_row_gap',
508 [
509 'label' => esc_html__('Column Gap', 'king-addons'),
510 'type' => Controls_Manager::SLIDER,
511 'size_units' => ['px', 'em'],
512 'range' => [
513 'px' => [
514 'min' => 0,
515 'max' => 50,
516 ],
517 ],
518 'selectors' => [
519 '{{WRAPPER}} .woocommerce-checkout .form-row-first' => 'padding-right: {{SIZE}}{{UNIT}};',
520 '{{WRAPPER}} .woocommerce-checkout .form-row-last' => 'padding-left: {{SIZE}}{{UNIT}};',
521 ],
522 ]
523 );
524
525 $this->end_controls_section();
526
527 // Place Order Button Style
528 $this->start_controls_section(
529 'section_style_place_order',
530 [
531 'label' => esc_html__('Place Order Button', 'king-addons'),
532 'tab' => Controls_Manager::TAB_STYLE,
533 ]
534 );
535
536 $this->start_controls_tabs('place_order_tabs');
537
538 $this->start_controls_tab(
539 'place_order_normal',
540 [
541 'label' => esc_html__('Normal', 'king-addons'),
542 ]
543 );
544
545 $this->add_control(
546 'place_order_text_color',
547 [
548 'label' => esc_html__('Text Color', 'king-addons'),
549 'type' => Controls_Manager::COLOR,
550 'selectors' => [
551 '{{WRAPPER}} #place_order' => 'color: {{VALUE}};',
552 ],
553 ]
554 );
555
556 $this->add_control(
557 'place_order_bg_color',
558 [
559 'label' => esc_html__('Background Color', 'king-addons'),
560 'type' => Controls_Manager::COLOR,
561 'selectors' => [
562 '{{WRAPPER}} #place_order' => 'background-color: {{VALUE}};',
563 ],
564 ]
565 );
566
567 $this->end_controls_tab();
568
569 $this->start_controls_tab(
570 'place_order_hover',
571 [
572 'label' => esc_html__('Hover', 'king-addons'),
573 ]
574 );
575
576 $this->add_control(
577 'place_order_hover_text_color',
578 [
579 'label' => esc_html__('Text Color', 'king-addons'),
580 'type' => Controls_Manager::COLOR,
581 'selectors' => [
582 '{{WRAPPER}} #place_order:hover' => 'color: {{VALUE}};',
583 ],
584 ]
585 );
586
587 $this->add_control(
588 'place_order_hover_bg_color',
589 [
590 'label' => esc_html__('Background Color', 'king-addons'),
591 'type' => Controls_Manager::COLOR,
592 'selectors' => [
593 '{{WRAPPER}} #place_order:hover' => 'background-color: {{VALUE}};',
594 ],
595 ]
596 );
597
598 $this->end_controls_tab();
599
600 $this->end_controls_tabs();
601
602 $this->add_group_control(
603 Group_Control_Typography::get_type(),
604 [
605 'name' => 'place_order_typography',
606 'selector' => '{{WRAPPER}} #place_order',
607 'separator' => 'before',
608 ]
609 );
610
611 $this->add_responsive_control(
612 'place_order_padding',
613 [
614 'label' => esc_html__('Padding', 'king-addons'),
615 'type' => Controls_Manager::DIMENSIONS,
616 'size_units' => ['px', 'em'],
617 'selectors' => [
618 '{{WRAPPER}} #place_order' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
619 ],
620 ]
621 );
622
623 $this->add_responsive_control(
624 'place_order_border_radius',
625 [
626 'label' => esc_html__('Border Radius', 'king-addons'),
627 'type' => Controls_Manager::DIMENSIONS,
628 'size_units' => ['px', '%'],
629 'selectors' => [
630 '{{WRAPPER}} #place_order' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
631 ],
632 ]
633 );
634
635 $this->add_group_control(
636 Group_Control_Border::get_type(),
637 [
638 'name' => 'place_order_border',
639 'selector' => '{{WRAPPER}} #place_order',
640 ]
641 );
642
643 $this->add_responsive_control(
644 'place_order_margin',
645 [
646 'label' => esc_html__('Margin', 'king-addons'),
647 'type' => Controls_Manager::DIMENSIONS,
648 'size_units' => ['px', 'em'],
649 'selectors' => [
650 '{{WRAPPER}} #place_order' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
651 ],
652 ]
653 );
654
655 $this->add_control(
656 'place_order_full_width',
657 [
658 'label' => esc_html__('Full Width', 'king-addons'),
659 'type' => Controls_Manager::SWITCHER,
660 'selectors' => [
661 '{{WRAPPER}} #place_order' => 'width: 100%;',
662 ],
663 ]
664 );
665
666 $this->end_controls_section();
667 }
668
669 /**
670 * Render widget output.
671 *
672 * @return void
673 */
674 protected function render(): void
675 {
676 if (!class_exists('WooCommerce')) {
677 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
678 echo '<div class="king-addons-woo-builder-notice">' . esc_html__('WooCommerce is required for this widget.', 'king-addons') . '</div>';
679 }
680 return;
681 }
682
683 // In editor mode, ensure WC session and cart are available
684 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
685 if (is_null(WC()->cart)) {
686 wc_load_cart();
687 }
688 }
689
690 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
691 echo do_shortcode('[woocommerce_checkout]');
692 }
693 }
694