PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
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 / Woo_Checkout_ACF_Fields / Woo_Checkout_ACF_Fields.php

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

260 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Checkout ACF Extra Fields widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Widget_Base;
12 use King_Addons\Core;
13 use King_Addons\Woo_Builder\ACF_Fields;
14 use King_Addons\Woo_Builder\Context as Woo_Context;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 /**
21 * Placeholder ACF fields for checkout (Pro-only rendering).
22 */
23 class Woo_Checkout_ACF_Fields extends Widget_Base
24 {
25 /**
26 * Register Pro-only controls (placeholder).
27 *
28 * Pro overrides this method to add premium controls without using parent::register_controls().
29 *
30 * @return void
31 */
32 public function register_pro_controls(): void
33 {
34 // Intentionally empty in Free.
35 }
36
37 /**
38 * Widget slug.
39 *
40 * @return string
41 */
42 public function get_name(): string
43 {
44 return 'woo_checkout_acf_fields';
45 }
46
47 /**
48 * Widget title.
49 *
50 * @return string
51 */
52 public function get_title(): string
53 {
54 return esc_html__('Checkout ACF Extra Fields', 'king-addons');
55 }
56
57 /**
58 * Widget icon.
59 *
60 * @return string
61 */
62 public function get_icon(): string
63 {
64 return 'king-addons-icon king-addons-woo-checkout-acf-fields';
65 }
66
67 /**
68 * Styles.
69 *
70 * @return array<int,string>
71 */
72 public function get_style_depends(): array
73 {
74 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-acf-fields-style'];
75 }
76
77 /**
78 * Scripts: moves the fields into the checkout form when it rendered first.
79 *
80 * @return array<int,string>
81 */
82 public function get_script_depends(): array
83 {
84 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-acf-fields-script'];
85 }
86
87 /**
88 * Widget categories.
89 *
90 * @return array<int,string>
91 */
92 public function get_categories(): array
93 {
94 return ['king-addons-woo-builder'];
95 }
96
97 /**
98 * Register controls.
99 *
100 * @return void
101 */
102 public function get_custom_help_url()
103 {
104 return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue';
105 }
106
107 protected function register_controls(): void
108 {
109 $this->start_controls_section(
110 'section_content',
111 [
112 'label' => esc_html__('Content', 'king-addons'),
113 'tab' => Controls_Manager::TAB_CONTENT,
114 ]
115 );
116
117 $this->add_control(
118 'heading',
119 [
120 'label' => esc_html__('Heading', 'king-addons'),
121 'type' => Controls_Manager::TEXT,
122 'dynamic' => ['active' => true],
123 'default' => esc_html__('Extra Information', 'king-addons'),
124 ]
125 );
126
127 $this->add_control(
128 'field_keys',
129 [
130 'label' => esc_html__('ACF Field Keys (Pro)', 'king-addons'),
131 'type' => Controls_Manager::TEXT,
132 'placeholder' => 'field_123abc, my_field',
133 ]
134 );
135
136 $this->add_control(
137 'placement',
138 [
139 'label' => esc_html__('Placement', 'king-addons'),
140 'description' => esc_html__('Where the fields appear inside the checkout form. They have to be inside it to be saved with the order.', 'king-addons'),
141 'type' => Controls_Manager::SELECT,
142 'options' => [
143 'before_billing' => esc_html__('Before billing', 'king-addons'),
144 'after_billing' => esc_html__('After billing', 'king-addons'),
145 'before_shipping' => esc_html__('Before shipping', 'king-addons'),
146 'after_shipping' => esc_html__('After shipping', 'king-addons'),
147 'before_order' => esc_html__('Before order notes', 'king-addons'),
148 'after_order' => esc_html__('After order notes', 'king-addons'),
149 ],
150 'default' => 'after_order',
151 ]
152 );
153
154 $this->add_control(
155 'required_notice',
156 [
157 'label' => sprintf(__('Show required mark %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
158 'type' => Controls_Manager::SWITCHER,
159 'return_value' => 'yes',
160 // ACF always printed the mark; the switch now controls it.
161 'default' => 'yes',
162 ]
163 );
164
165 $this->end_controls_section();
166
167 $this->start_controls_section(
168 'section_style',
169 [
170 'label' => esc_html__('Style', 'king-addons'),
171 'tab' => Controls_Manager::TAB_STYLE,
172 ]
173 );
174
175 // The fields are printed inside the checkout form, outside this widget's
176 // wrapper, so {{WRAPPER}} cannot reach them there. The block carries a
177 // class with the widget id instead.
178 $this->add_control(
179 'gap',
180 [
181 'label' => esc_html__('Fields gap', 'king-addons'),
182 'type' => Controls_Manager::SLIDER,
183 'range' => [
184 'px' => ['min' => 0, 'max' => 40],
185 ],
186 'selectors' => [
187 '.ka-acf-block.ka-acf-block-{{ID}}' => '--ka-acf-gap: {{SIZE}}{{UNIT}};',
188 ],
189 ]
190 );
191
192 $this->add_control(
193 'label_color',
194 [
195 'label' => esc_html__('Label color', 'king-addons'),
196 'type' => Controls_Manager::COLOR,
197 'selectors' => [
198 '.ka-acf-block.ka-acf-block-{{ID}} .acf-field .acf-label label, .ka-acf-block.ka-acf-block-{{ID}} .acf-field .acf-input label' => 'color: {{VALUE}};',
199 ],
200 ]
201 );
202
203 $this->add_control(
204 'required_color',
205 [
206 'label' => esc_html__('Required mark color', 'king-addons'),
207 'type' => Controls_Manager::COLOR,
208 'selectors' => [
209 '.ka-acf-block.ka-acf-block-{{ID}} .acf-required' => 'color: {{VALUE}};',
210 ],
211 ]
212 );
213
214 $this->end_controls_section();
215
216 // Allow Pro to add additional controls without using parent::register_controls().
217 $this->register_pro_controls();
218 }
219
220 /**
221 * Render widget output (free notice).
222 *
223 * @return void
224 */
225 protected function render(): void
226 {
227 if (!Woo_Context::maybe_render_context_notice('checkout')) {
228 return;
229 }
230
231 $in_builder = class_exists('King_Addons\\Woo_Builder\\Context') && Woo_Context::is_editing_template_type('checkout');
232 if (!function_exists('is_checkout') || (!is_checkout() && !$in_builder) || (function_exists('is_order_received_page') && is_order_received_page())) {
233 return;
234 }
235
236 if (!king_addons_can_use_pro()) {
237 if (Woo_Context::is_editor()) {
238 echo '<div class="king-addons-woo-builder-notice">';
239 echo esc_html__('ACF extra fields for checkout are available in Pro.', 'king-addons');
240 echo '</div>';
241 }
242 return;
243 }
244
245 if (!class_exists('King_Addons\\Woo_Builder\\ACF_Fields')) {
246 require_once KING_ADDONS_PATH . 'includes/helpers/Woo_Builder/ACF_Fields.php';
247 }
248
249 // Printing, validation and saving to the order live in the helper: the
250 // order is created by a separate request in which no widget renders.
251 ACF_Fields::render_checkout($this->get_settings_for_display(), (string) $this->get_id());
252 }
253 }
254
255
256
257
258
259
260