PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.63
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.63
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.63, at includes/widgets/Woo_Checkout_Payment/Woo_Checkout_Payment.php

357 lines 10.4 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 'eicon-credit-card';
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
302 if ($can_pro) {
303 $accordion = (!empty($settings['enable_accordion']) && 'yes' === $settings['enable_accordion']) ? 'true' : 'false';
304 $icons = [];
305 foreach ($settings['gateway_icons'] ?? [] as $item) {
306 $gid = sanitize_key($item['gateway_id'] ?? '');
307 $url = isset($item['icon_url']) ? esc_url_raw($item['icon_url']) : '';
308 if ($gid && $url) {
309 $icons[$gid] = $url;
310 }
311 }
312 $buttons = [];
313 foreach ($settings['place_order_texts'] ?? [] as $item) {
314 $gid = sanitize_key($item['gateway_id'] ?? '');
315 $txt = isset($item['button_text']) ? sanitize_text_field($item['button_text']) : '';
316 if ($gid && $txt) {
317 $buttons[$gid] = $txt;
318 }
319 }
320 $descs = [];
321 foreach ($settings['custom_descriptions'] ?? [] as $item) {
322 $gid = sanitize_key($item['gateway_id'] ?? '');
323 $txt = isset($item['text']) ? wp_kses_post($item['text']) : '';
324 if ($gid && $txt) {
325 $descs[$gid] = $txt;
326 }
327 }
328
329 $attrs['data-ka-accordion'] = $accordion;
330 if (!empty($icons)) {
331 $attrs['data-ka-icons'] = esc_attr(wp_json_encode($icons));
332 }
333 if (!empty($buttons)) {
334 $attrs['data-ka-placeorder'] = esc_attr(wp_json_encode($buttons));
335 }
336 if (!empty($descs)) {
337 $attrs['data-ka-descriptions'] = esc_attr(wp_json_encode($descs));
338 }
339 }
340
341 $attr_str = '';
342 foreach ($attrs as $key => $val) {
343 $attr_str .= ' ' . $key . '="' . esc_attr($val) . '"';
344 }
345
346 echo '<div' . $attr_str . '>';
347 wc_get_template('checkout/payment.php', ['checkout' => $checkout]);
348 echo '</div>';
349 }
350 }
351
352
353
354
355
356
357