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

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

377 lines 11.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 Payment widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Border;
12 use Elementor\Group_Control_Box_Shadow;
13 use Elementor\Group_Control_Typography;
14 use King_Addons\Core;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 /**
21 * Displays checkout payment methods.
22 */
23 class Woo_Checkout_Payment extends Abstract_Checkout_Widget
24 {
25 /**
26 * Widget slug.
27 *
28 * @return string
29 */
30 public function get_name(): string
31 {
32 return 'woo_checkout_payment';
33 }
34
35 /**
36 * Widget title.
37 *
38 * @return string
39 */
40 public function get_title(): string
41 {
42 return esc_html__('Checkout Payment', 'king-addons');
43 }
44
45 /**
46 * Widget icon.
47 *
48 * @return string
49 */
50 public function get_icon(): string
51 {
52 return 'king-addons-icon king-addons-woo-checkout-payment';
53 }
54
55 /**
56 * Categories.
57 *
58 * @return array<int, string>
59 */
60 public function get_categories(): array
61 {
62 return ['king-addons-woo-builder'];
63 }
64
65 /**
66 * Style dependencies.
67 *
68 * @return array<int, string>
69 */
70 public function get_style_depends(): array
71 {
72 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-payment-style'];
73 }
74
75 /**
76 * Script dependencies.
77 *
78 * @return array<int, string>
79 */
80 public function get_script_depends(): array
81 {
82 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-checkout-payment-script'];
83 }
84
85 /**
86 * Register controls.
87 *
88 * @return void
89 */
90 protected function register_controls(): void
91 {
92 $this->start_controls_section(
93 'section_behavior',
94 [
95 'label' => esc_html__('Behavior', 'king-addons'),
96 'tab' => Controls_Manager::TAB_CONTENT,
97 ]
98 );
99
100 $this->add_control(
101 'enable_accordion',
102 [
103 'label' => sprintf(__('Accordion payments (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
104 'type' => Controls_Manager::SWITCHER,
105 'return_value' => 'yes',
106 ]
107 );
108
109 $this->add_control(
110 'gateway_icons',
111 [
112 'label' => esc_html__('Payment icons (Pro)', 'king-addons'),
113 'type' => Controls_Manager::REPEATER,
114 'condition' => [
115 'enable_accordion' => 'yes',
116 ],
117 'fields' => [
118 [
119 'name' => 'gateway_id',
120 'label' => esc_html__('Gateway ID', 'king-addons'),
121 'type' => Controls_Manager::TEXT,
122 'placeholder' => 'stripe',
123 ],
124 [
125 'name' => 'icon_url',
126 'label' => esc_html__('Icon URL', 'king-addons'),
127 'type' => Controls_Manager::TEXT,
128 'placeholder' => 'https://…/visa.svg',
129 ],
130 ],
131 'title_field' => '{{ gateway_id }}',
132 ]
133 );
134
135 $this->add_control(
136 'custom_descriptions',
137 [
138 'label' => esc_html__('Custom descriptions (Pro)', 'king-addons'),
139 'type' => Controls_Manager::REPEATER,
140 'fields' => [
141 [
142 'name' => 'gateway_id',
143 'label' => esc_html__('Gateway ID', 'king-addons'),
144 'type' => Controls_Manager::TEXT,
145 'placeholder' => 'stripe',
146 ],
147 [
148 'name' => 'text',
149 'label' => esc_html__('Description', 'king-addons'),
150 'type' => Controls_Manager::TEXTAREA,
151 'rows' => 2,
152 ],
153 ],
154 'title_field' => '{{ gateway_id }}',
155 ]
156 );
157
158 $this->add_control(
159 'place_order_texts',
160 [
161 'label' => esc_html__('Place order text per gateway (Pro)', 'king-addons'),
162 'type' => Controls_Manager::REPEATER,
163 'condition' => [
164 'enable_accordion' => 'yes',
165 ],
166 'fields' => [
167 [
168 'name' => 'gateway_id',
169 'label' => esc_html__('Gateway ID', 'king-addons'),
170 'type' => Controls_Manager::TEXT,
171 'placeholder' => 'stripe',
172 ],
173 [
174 'name' => 'button_text',
175 'label' => esc_html__('Button text', 'king-addons'),
176 'type' => Controls_Manager::TEXT,
177 'placeholder' => esc_html__('Pay now', 'king-addons'),
178 ],
179 ],
180 'title_field' => '{{ gateway_id }}',
181 ]
182 );
183
184 $this->end_controls_section();
185
186 $this->start_controls_section(
187 'section_style',
188 [
189 'label' => esc_html__('Payment Box', 'king-addons'),
190 'tab' => Controls_Manager::TAB_STYLE,
191 ]
192 );
193
194 $this->add_group_control(
195 Group_Control_Typography::get_type(),
196 [
197 'name' => 'text_typography',
198 'selector' => '{{WRAPPER}} .ka-woo-checkout-payment',
199 ]
200 );
201
202 $this->add_control(
203 'text_color',
204 [
205 'label' => esc_html__('Text Color', 'king-addons'),
206 'type' => Controls_Manager::COLOR,
207 'selectors' => [
208 '{{WRAPPER}} .ka-woo-checkout-payment' => 'color: {{VALUE}};',
209 ],
210 ]
211 );
212
213 $this->add_group_control(
214 Group_Control_Border::get_type(),
215 [
216 'name' => 'box_border',
217 'selector' => '{{WRAPPER}} .ka-woo-checkout-payment',
218 ]
219 );
220
221 $this->add_group_control(
222 Group_Control_Box_Shadow::get_type(),
223 [
224 'name' => 'box_shadow',
225 'selector' => '{{WRAPPER}} .ka-woo-checkout-payment',
226 ]
227 );
228
229 $this->add_control(
230 'box_padding',
231 [
232 'label' => esc_html__('Padding', 'king-addons'),
233 'type' => Controls_Manager::DIMENSIONS,
234 'size_units' => ['px', 'em', '%'],
235 'selectors' => [
236 '{{WRAPPER}} .ka-woo-checkout-payment' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
237 ],
238 ]
239 );
240
241 $this->add_control(
242 'method_gap',
243 [
244 'label' => esc_html__('Methods gap', 'king-addons'),
245 'type' => Controls_Manager::SLIDER,
246 'range' => [
247 'px' => ['min' => 0, 'max' => 40],
248 ],
249 'selectors' => [
250 '{{WRAPPER}} .ka-woo-checkout-payment .wc_payment_methods' => 'gap: {{SIZE}}{{UNIT}};',
251 ],
252 ]
253 );
254
255 $this->add_group_control(
256 Group_Control_Typography::get_type(),
257 [
258 'name' => 'label_typography',
259 'selector' => '{{WRAPPER}} .ka-woo-checkout-payment .wc_payment_method label',
260 'label' => esc_html__('Label Typography', 'king-addons'),
261 ]
262 );
263
264 $this->add_control(
265 'desc_color',
266 [
267 'label' => esc_html__('Description Color', 'king-addons'),
268 'type' => Controls_Manager::COLOR,
269 'selectors' => [
270 '{{WRAPPER}} .ka-woo-checkout-payment .ka-wc-payment__custom-desc' => 'color: {{VALUE}};',
271 ],
272 ]
273 );
274
275 $this->end_controls_section();
276 }
277
278 /**
279 * Render widget output.
280 *
281 * @return void
282 */
283 protected function render(): void
284 {
285 if (!$this->should_render()) {
286 $this->render_missing_checkout_notice();
287 return;
288 }
289
290 if (!function_exists('WC')) {
291 return;
292 }
293
294 $checkout = WC()->checkout();
295 $settings = $this->get_settings_for_display();
296 $can_pro = king_addons_can_use_pro();
297
298 $attrs = [
299 'class' => 'ka-woo-checkout-payment',
300 ];
301 if (class_exists('King_Addons\\Woo_Builder\\Context') && \King_Addons\Woo_Builder\Context::template_has_widget('woo_checkout_place_order', 'checkout')) {
302 $attrs['class'] .= ' ka-woo-checkout-payment--external-place-order';
303 }
304
305 if ($can_pro) {
306 $accordion = (!empty($settings['enable_accordion']) && 'yes' === $settings['enable_accordion']) ? 'true' : 'false';
307 $icons = [];
308 foreach ($settings['gateway_icons'] ?? [] as $item) {
309 $gid = sanitize_key($item['gateway_id'] ?? '');
310 // Cast first: a settings value that is not a string (a URL
311 // control's array, say) made esc_url_raw() throw a TypeError
312 // and took the whole checkout page down with a 500.
313 $raw_url = $item['icon_url'] ?? '';
314 if (is_array($raw_url)) {
315 $raw_url = $raw_url['url'] ?? '';
316 }
317 $url = is_scalar($raw_url) ? esc_url_raw((string) $raw_url) : '';
318 if ($gid && $url) {
319 $icons[$gid] = $url;
320 }
321 }
322 $buttons = [];
323 foreach ($settings['place_order_texts'] ?? [] as $item) {
324 $gid = sanitize_key($item['gateway_id'] ?? '');
325 $txt = isset($item['button_text']) ? sanitize_text_field($item['button_text']) : '';
326 if ($gid && $txt) {
327 $buttons[$gid] = $txt;
328 }
329 }
330 $descs = [];
331 foreach ($settings['custom_descriptions'] ?? [] as $item) {
332 $gid = sanitize_key($item['gateway_id'] ?? '');
333 $txt = isset($item['text']) ? wp_kses_post($item['text']) : '';
334 if ($gid && $txt) {
335 $descs[$gid] = $txt;
336 }
337 }
338
339 $attrs['data-ka-accordion'] = $accordion;
340 if (!empty($icons)) {
341 $attrs['data-ka-icons'] = wp_json_encode($icons);
342 }
343 if (!empty($buttons)) {
344 $attrs['data-ka-placeorder'] = wp_json_encode($buttons);
345 }
346 if (!empty($descs)) {
347 $attrs['data-ka-descriptions'] = wp_json_encode($descs);
348 }
349 }
350
351 // Single escaping only: these values are escaped here, once.
352 $attr_str = '';
353 foreach ($attrs as $key => $val) {
354 $attr_str .= ' ' . esc_attr($key) . '="' . esc_attr((string) $val) . '"';
355 }
356
357 echo '<div' . $attr_str . '>';
358 // checkout/payment.php also expects $order_button_text; WooCommerce's own
359 // woocommerce_checkout_payment() passes it. Without it the template
360 // warned three times per render and printed a button with no label.
361 wc_get_template(
362 'checkout/payment.php',
363 [
364 'checkout' => $checkout,
365 'order_button_text' => apply_filters('woocommerce_order_button_text', __('Place order', 'woocommerce')),
366 ]
367 );
368 echo '</div>';
369 }
370 }
371
372
373
374
375
376
377