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 / 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.65, at includes/widgets/Quick_View_Product/Quick_View_Product.php

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