PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
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 / Quick_View_Product / Quick_View_Product.php

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

503 lines 14.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Quick View Product Widget (Free).
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 Elementor\Widget_Base;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 require_once __DIR__ . '/ajax-handler.php';
21
22 /**
23 * Renders the Quick View Product widget.
24 */
25 class Quick_View_Product extends Widget_Base
26 {
27 /**
28 * Widget slug.
29 *
30 * @return string
31 */
32 public function get_name(): string
33 {
34 return 'king-addons-quick-view-product';
35 }
36
37 /**
38 * Widget title.
39 *
40 * @return string
41 */
42 public function get_title(): string
43 {
44 return esc_html__('Quick View Product', 'king-addons');
45 }
46
47 /**
48 * Widget icon.
49 *
50 * @return string
51 */
52 public function get_icon(): string
53 {
54 return 'king-addons-icon king-addons-quick-view-product';
55 }
56
57 /**
58 * Script dependencies.
59 *
60 * @return array<int, string>
61 */
62 public function get_script_depends(): array
63 {
64 return [
65 'jquery',
66 'wc-add-to-cart-variation',
67 KING_ADDONS_ASSETS_UNIQUE_KEY . '-quick-view-product-script',
68 ];
69 }
70
71 /**
72 * Style dependencies.
73 *
74 * @return array<int, string>
75 */
76 public function get_style_depends(): array
77 {
78 return [
79 KING_ADDONS_ASSETS_UNIQUE_KEY . '-quick-view-product-style',
80 ];
81 }
82
83 /**
84 * Widget categories.
85 *
86 * @return array<int, string>
87 */
88 public function get_categories(): array
89 {
90 return ['king-addons'];
91 }
92
93 /**
94 * Widget keywords.
95 *
96 * @return array<int, string>
97 */
98 public function get_keywords(): array
99 {
100 return ['woocommerce', 'product', 'quick view', 'modal'];
101 }
102
103 /**
104 * Register controls.
105 *
106 * @return void
107 */
108 public function register_controls(): void
109 {
110 $this->register_content_controls();
111 $this->register_style_button_controls();
112 $this->register_style_modal_controls();
113 $this->register_pro_notice_controls();
114 }
115
116 /**
117 * Render widget output.
118 *
119 * @return void
120 */
121 public function render(): void
122 {
123 if (!class_exists('\WooCommerce')) {
124 return;
125 }
126
127 $settings = $this->get_settings_for_display();
128 $product_id = $this->resolve_product_id($settings);
129
130 if (!$product_id) {
131 return;
132 }
133
134 $button_text = $settings['kng_button_text'] ?? esc_html__('Quick View', 'king-addons');
135 $wrapper_classes = ['king-addons-quick-view'];
136 $nonce = wp_create_nonce('king_addons_qv');
137 $settings_payload = wp_json_encode([
138 'show_image' => $settings['kng_show_image'] ?? 'yes',
139 'show_price' => $settings['kng_show_price'] ?? 'yes',
140 'show_rating' => $settings['kng_show_rating'] ?? 'yes',
141 'show_excerpt' => $settings['kng_show_excerpt'] ?? 'yes',
142 'show_button' => $settings['kng_show_button'] ?? 'yes',
143 'pro_gallery' => 'no',
144 'pro_variations' => 'no',
145 'pro_sticky_cta' => 'no',
146 ]);
147
148 ?>
149 <div class="<?php echo esc_attr(implode(' ', $wrapper_classes)); ?>"
150 data-product-id="<?php echo esc_attr((string) $product_id); ?>"
151 data-nonce="<?php echo esc_attr($nonce); ?>"
152 data-qv-settings="<?php echo esc_attr($settings_payload); ?>">
153 <button type="button" class="king-addons-quick-view__trigger">
154 <span class="king-addons-quick-view__label"><?php echo esc_html($button_text); ?></span>
155 <span class="king-addons-quick-view__spinner" aria-hidden="true"></span>
156 </button>
157 <div class="king-addons-quick-view__modal" role="dialog" aria-modal="true" aria-label="<?php echo esc_attr__('Product quick view', 'king-addons'); ?>">
158 <div class="king-addons-quick-view__overlay"></div>
159 <div class="king-addons-quick-view__content">
160 <button type="button" class="king-addons-quick-view__close" aria-label="<?php echo esc_attr__('Close', 'king-addons'); ?>">×</button>
161 <div class="king-addons-quick-view__body">
162 <div class="king-addons-quick-view__loader"></div>
163 <div class="king-addons-quick-view__product"></div>
164 </div>
165 </div>
166 </div>
167 </div>
168 <?php
169 }
170
171 /**
172 * Content controls.
173 *
174 * @return void
175 */
176 protected function register_content_controls(): void
177 {
178 $this->start_controls_section(
179 'kng_content_section',
180 [
181 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Product', 'king-addons'),
182 'tab' => Controls_Manager::TAB_CONTENT,
183 ]
184 );
185
186 $this->add_control(
187 'kng_use_current_product',
188 [
189 'label' => esc_html__('Use Current Product (Single)', 'king-addons'),
190 'type' => Controls_Manager::SWITCHER,
191 'return_value' => 'yes',
192 'default' => 'yes',
193 ]
194 );
195
196 $this->add_control(
197 'kng_product_id',
198 [
199 'label' => esc_html__('Product ID (fallback)', 'king-addons'),
200 'type' => Controls_Manager::NUMBER,
201 'min' => 1,
202 'step' => 1,
203 'condition' => [
204 'kng_use_current_product!' => 'yes',
205 ],
206 ]
207 );
208
209 $this->add_control(
210 'kng_show_image',
211 [
212 'label' => esc_html__('Show Image', 'king-addons'),
213 'type' => Controls_Manager::SWITCHER,
214 'return_value' => 'yes',
215 'default' => 'yes',
216 ]
217 );
218
219 $this->add_control(
220 'kng_show_price',
221 [
222 'label' => esc_html__('Show Price', 'king-addons'),
223 'type' => Controls_Manager::SWITCHER,
224 'return_value' => 'yes',
225 'default' => 'yes',
226 ]
227 );
228
229 $this->add_control(
230 'kng_show_rating',
231 [
232 'label' => esc_html__('Show Rating', 'king-addons'),
233 'type' => Controls_Manager::SWITCHER,
234 'return_value' => 'yes',
235 'default' => 'yes',
236 ]
237 );
238
239 $this->add_control(
240 'kng_show_excerpt',
241 [
242 'label' => esc_html__('Show Short Description', 'king-addons'),
243 'type' => Controls_Manager::SWITCHER,
244 'return_value' => 'yes',
245 'default' => 'yes',
246 ]
247 );
248
249 $this->add_control(
250 'kng_show_button',
251 [
252 'label' => esc_html__('Show Add to Cart', 'king-addons'),
253 'type' => Controls_Manager::SWITCHER,
254 'return_value' => 'yes',
255 'default' => 'yes',
256 ]
257 );
258
259 $this->add_control(
260 'kng_button_text',
261 [
262 'label' => esc_html__('Button Text', 'king-addons'),
263 'type' => Controls_Manager::TEXT,
264 'default' => esc_html__('Quick View', 'king-addons'),
265 ]
266 );
267
268 $this->end_controls_section();
269 }
270
271 /**
272 * Button styles.
273 *
274 * @return void
275 */
276 protected function register_style_button_controls(): void
277 {
278 $this->start_controls_section(
279 'kng_style_button_section',
280 [
281 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Button', 'king-addons'),
282 'tab' => Controls_Manager::TAB_STYLE,
283 ]
284 );
285
286 $this->add_control(
287 'kng_button_alignment',
288 [
289 'label' => esc_html__('Alignment', 'king-addons'),
290 'type' => Controls_Manager::CHOOSE,
291 'options' => [
292 'flex-start' => [
293 'title' => esc_html__('Left', 'king-addons'),
294 'icon' => 'eicon-h-align-left',
295 ],
296 'center' => [
297 'title' => esc_html__('Center', 'king-addons'),
298 'icon' => 'eicon-h-align-center',
299 ],
300 'flex-end' => [
301 'title' => esc_html__('Right', 'king-addons'),
302 'icon' => 'eicon-h-align-right',
303 ],
304 ],
305 'default' => 'flex-start',
306 'selectors' => [
307 '{{WRAPPER}} .king-addons-quick-view' => 'justify-content: {{VALUE}};',
308 ],
309 ]
310 );
311
312 $this->add_group_control(
313 Group_Control_Typography::get_type(),
314 [
315 'name' => 'kng_button_typography',
316 'selector' => '{{WRAPPER}} .king-addons-quick-view__trigger',
317 ]
318 );
319
320 $this->add_control(
321 'kng_button_color',
322 [
323 'label' => esc_html__('Text Color', 'king-addons'),
324 'type' => Controls_Manager::COLOR,
325 'selectors' => [
326 '{{WRAPPER}} .king-addons-quick-view__trigger' => 'color: {{VALUE}};',
327 ],
328 ]
329 );
330
331 $this->add_control(
332 'kng_button_bg',
333 [
334 'label' => esc_html__('Background', 'king-addons'),
335 'type' => Controls_Manager::COLOR,
336 'selectors' => [
337 '{{WRAPPER}} .king-addons-quick-view__trigger' => 'background-color: {{VALUE}};',
338 ],
339 ]
340 );
341
342 $this->add_control(
343 'kng_button_color_hover',
344 [
345 'label' => esc_html__('Hover Text Color', 'king-addons'),
346 'type' => Controls_Manager::COLOR,
347 'selectors' => [
348 '{{WRAPPER}} .king-addons-quick-view__trigger:hover' => 'color: {{VALUE}};',
349 ],
350 ]
351 );
352
353 $this->add_control(
354 'kng_button_bg_hover',
355 [
356 'label' => esc_html__('Hover Background', 'king-addons'),
357 'type' => Controls_Manager::COLOR,
358 'selectors' => [
359 '{{WRAPPER}} .king-addons-quick-view__trigger:hover' => 'background-color: {{VALUE}};',
360 ],
361 ]
362 );
363
364 $this->add_group_control(
365 Group_Control_Border::get_type(),
366 [
367 'name' => 'kng_button_border',
368 'selector' => '{{WRAPPER}} .king-addons-quick-view__trigger',
369 ]
370 );
371
372 $this->add_control(
373 'kng_button_radius',
374 [
375 'label' => esc_html__('Border Radius', 'king-addons'),
376 'type' => Controls_Manager::SLIDER,
377 'size_units' => ['px', '%'],
378 'range' => [
379 'px' => ['min' => 0, 'max' => 50],
380 '%' => ['min' => 0, 'max' => 100],
381 ],
382 'selectors' => [
383 '{{WRAPPER}} .king-addons-quick-view__trigger' => 'border-radius: {{SIZE}}{{UNIT}};',
384 ],
385 ]
386 );
387
388 $this->end_controls_section();
389 }
390
391 /**
392 * Modal styles.
393 *
394 * @return void
395 */
396 protected function register_style_modal_controls(): void
397 {
398 $this->start_controls_section(
399 'kng_style_modal_section',
400 [
401 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Modal', 'king-addons'),
402 'tab' => Controls_Manager::TAB_STYLE,
403 ]
404 );
405
406 $this->add_control(
407 'kng_overlay_color',
408 [
409 'label' => esc_html__('Overlay Color', 'king-addons'),
410 'type' => Controls_Manager::COLOR,
411 'selectors' => [
412 '{{WRAPPER}} .king-addons-quick-view__overlay' => 'background-color: {{VALUE}};',
413 ],
414 ]
415 );
416
417 $this->add_control(
418 'kng_modal_bg',
419 [
420 'label' => esc_html__('Modal Background', 'king-addons'),
421 'type' => Controls_Manager::COLOR,
422 'selectors' => [
423 '{{WRAPPER}} .king-addons-quick-view__content' => 'background-color: {{VALUE}};',
424 ],
425 ]
426 );
427
428 $this->add_group_control(
429 Group_Control_Box_Shadow::get_type(),
430 [
431 'name' => 'kng_modal_shadow',
432 'selector' => '{{WRAPPER}} .king-addons-quick-view__content',
433 ]
434 );
435
436 $this->add_control(
437 'kng_modal_radius',
438 [
439 'label' => esc_html__('Modal Border Radius', 'king-addons'),
440 'type' => Controls_Manager::SLIDER,
441 'size_units' => ['px', '%'],
442 'range' => [
443 'px' => ['min' => 0, 'max' => 40],
444 '%' => ['min' => 0, 'max' => 100],
445 ],
446 'selectors' => [
447 '{{WRAPPER}} .king-addons-quick-view__content' => 'border-radius: {{SIZE}}{{UNIT}};',
448 ],
449 ]
450 );
451
452 $this->end_controls_section();
453 }
454
455 /**
456 * Resolve product ID.
457 *
458 * @param array<string, mixed> $settings Settings.
459 *
460 * @return int
461 */
462 protected function resolve_product_id(array $settings): int
463 {
464 $use_current = ($settings['kng_use_current_product'] ?? 'yes') === 'yes';
465 if ($use_current && is_singular('product')) {
466 $product_id = get_the_ID();
467 if ($product_id) {
468 return (int) $product_id;
469 }
470 }
471
472 if (!empty($settings['kng_product_id'])) {
473 return (int) $settings['kng_product_id'];
474 }
475
476 return 0;
477 }
478
479 /**
480 * Pro notice section.
481 *
482 * @return void
483 */
484 public function register_pro_notice_controls(): void
485 {
486 if (!king_addons_freemius()->can_use_premium_code__premium_only()) {
487 Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'quick-view-product', [
488 'Gallery thumbnails and zoom',
489 'Variation picker inside modal',
490 'Sticky CTA and related products',
491 'Custom triggers and badges',
492 ]);
493 }
494 }
495 }
496
497
498
499
500
501
502
503