PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.1.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.1.4
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / modules / product-list / widgets / product-list.php

product-list.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 3.1.4, at modules/product-list/widgets/product-list.php

506 lines 17.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit\Modules\ProductList\Widgets;
4
5
6 use Elementor\Controls_Manager;
7 use UltimateStoreKit\Base\Module_Base;
8 use Elementor\Group_Control_Border;
9 use Elementor\Group_Control_Background;
10 use Elementor\Group_Control_Box_Shadow;
11 use Elementor\Group_Control_Image_Size;
12 use Elementor\Group_Control_Typography;
13 use UltimateStoreKit\traits\Global_Widget_Controls;
14 use UltimateStoreKit\traits\Global_Widget_Template;
15 // phpcs:disable WordPressVIPMinimum.Performance.WPQueryParams -- WordPressVIPMinimum targets the VIP platform, not the plugin directory. These exclusionary parameters come from a widget's own "exclude" control: the list is whatever the site owner picked in Elementor, applied to a bounded result set, not an unbounded catalogue scan.
16
17 // use UltimateStoreKit\traits\Global_Swiper_Template;
18 use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query;
19 use UltimateStoreKit\Classes\Utils;
20 use WP_Query;
21
22 if (!defined('ABSPATH')) {
23 exit;
24 }
25
26 // Exit if accessed directly
27
28 class Product_List extends Module_Base {
29 use Global_Widget_Controls;
30 use Global_Widget_Template;
31 // use Global_Swiper_Template;
32 use Group_Control_Query;
33
34 /**
35 * @var \WP_Query
36 */
37 private $_query = null;
38 public function get_name() {
39 return 'usk-product-list';
40 }
41
42 public function get_title() {
43 return esc_html__('Product List', 'ultimate-store-kit');
44 }
45
46 public function get_icon() {
47 return 'usk-widget-icon usk-icon-product-list';
48 }
49
50 public function get_categories() {
51 return ['ultimate-store-kit'];
52 }
53
54 public function get_keywords() {
55 return ['product', 'product list', 'table', 'wc', 'list'];
56 }
57
58 public function get_script_depends() {
59 return ['ultimate-store-kit-micromodal'];
60 }
61
62 public function get_style_depends() {
63 if ($this->usk_is_edit_mode()) {
64 return ['usk-all-styles'];
65 } else {
66 return ['usk-font', 'usk-product-list'];
67 }
68 }
69
70 public function get_custom_help_url() {
71 return 'https://youtu.be/qJQ9wfdoMKg';
72 }
73
74 public function get_query() {
75 return $this->_query;
76 }
77 public function has_widget_inner_wrapper(): bool {
78 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
79 }
80 protected function register_controls() {
81
82 $this->start_controls_section(
83 'section_woocommerce_layout',
84 [
85 'label' => esc_html__('Layout', 'ultimate-store-kit'),
86 ]
87 );
88 $this->add_responsive_control(
89 'items_gap',
90 [
91 'label' => esc_html__('Items Gap', 'ultimate-store-kit'),
92 'type' => Controls_Manager::SLIDER,
93 'selectors' => [
94 '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap' => 'grid-gap: {{SIZE}}px;',
95 ],
96 ]
97 );
98 $this->add_control(
99 'title_tags',
100 [
101 'label' => esc_html__('Title HTML Tag', 'ultimate-store-kit'),
102 'type' => Controls_Manager::SELECT,
103 'default' => 'h3',
104 'options' => ultimate_store_kit_title_tags(),
105 ]
106 );
107 $this->add_group_control(
108 Group_Control_Image_Size::get_type(),
109 [
110 'name' => 'image',
111 'label' => esc_html__('Image Size', 'ultimate-store-kit'),
112 'exclude' => ['custom'],
113 'default' => 'full',
114 ]
115 );
116
117 $this->end_controls_section();
118 $this->start_controls_section(
119 'section_post_query_builder',
120 [
121 'label' => __('Query', 'ultimate-store-kit'),
122 'tab' => Controls_Manager::TAB_CONTENT,
123 ]
124 );
125 $this->register_query_builder_controls();
126 $this->register_controls_wc_additional();
127 $this->end_controls_section();
128
129 $this->start_controls_section(
130 'section_woocommerce_additional',
131 [
132 'label' => esc_html__('Additional Options', 'ultimate-store-kit'),
133 ]
134 );
135 $this->start_controls_tabs(
136 'tabs_show_hide_content'
137 );
138 $this->start_controls_tab(
139 'show_content_tab',
140 [
141 'label' => esc_html__('Content', 'ultimate-store-kit'),
142 ]
143 );
144 $this->add_control(
145 'show_image',
146 [
147 'label' => esc_html__('Image', 'ultimate-store-kit'),
148 'type' => Controls_Manager::SWITCHER,
149 'return_value' => 'yes',
150 'default' => 'yes',
151 ]
152 );
153 $this->add_control(
154 'show_title',
155 [
156 'label' => esc_html__('Title', 'ultimate-store-kit'),
157 'type' => Controls_Manager::SWITCHER,
158 'return_value' => 'yes',
159 'default' => 'yes',
160 ]
161 );
162 $this->add_control(
163 'show_price',
164 [
165 'label' => esc_html__('Price', 'ultimate-store-kit'),
166 'type' => Controls_Manager::SWITCHER,
167 'default' => 'yes',
168 ]
169 );
170 $this->add_control(
171 'show_rating',
172 [
173 'label' => esc_html__('Rating', 'ultimate-store-kit'),
174 'type' => Controls_Manager::SWITCHER,
175 'default' => 'yes',
176 ]
177 );
178 $this->add_control(
179 'hide_customer_review',
180 [
181 'label' => esc_html__('Hide Review Text', 'ultimate-store-kit'),
182 'type' => Controls_Manager::SWITCHER,
183 'label_on' => esc_html__('Yes', 'ultimate-store-kit'),
184 'label_off' => esc_html__('No', 'ultimate-store-kit'),
185 // 'return_value' => 'yes',
186 'default' => 'yes',
187 'condition' => [
188 'show_rating' => 'yes',
189 ],
190 'selectors' => [
191 '{{WRAPPER}} .usk-recently-view-products .usk-rating .woocommerce-product-rating .woocommerce-review-link' => 'display:none',
192 ],
193 ]
194 );
195
196 $this->end_controls_tab();
197 $this->start_controls_tab(
198 'show_badge_tab',
199 [
200 'label' => esc_html__('Badge', 'ultimate-store-kit'),
201 ]
202 );
203 $this->add_control(
204 'show_sale_badge',
205 [
206 'label' => esc_html__('Sale', 'ultimate-store-kit'),
207 'type' => Controls_Manager::SWITCHER,
208 'default' => 'yes',
209 ]
210 );
211 $this->add_control(
212 'show_discount_badge',
213 [
214 'label' => esc_html__('Percentage', 'ultimate-store-kit'),
215 'type' => Controls_Manager::SWITCHER,
216 'default' => 'yes',
217 ]
218 );
219 $this->add_control(
220 'show_stock_status',
221 [
222 'label' => esc_html__('Stock Status', 'ultimate-store-kit'),
223 'type' => Controls_Manager::SWITCHER,
224 'default' => 'yes',
225 ]
226 );
227 $this->add_control(
228 'show_trending_badge',
229 [
230 'label' => esc_html__('Trending', 'ultimate-store-kit'),
231 'type' => Controls_Manager::SWITCHER,
232 'default' => 'yes',
233 ]
234 );
235 $this->add_control(
236 'show_new_badge',
237 [
238 'label' => esc_html__('New', 'ultimate-store-kit'),
239 'type' => Controls_Manager::SWITCHER,
240 'default' => 'yes',
241 ]
242 );
243 $this->add_control(
244 'newness_days',
245 [
246 'label' => esc_html__('Newness Days', 'ultimate-store-kit'),
247 'type' => Controls_Manager::NUMBER,
248 'default' => 90,
249 'description' => esc_html__('Define newness day from product created date; default newness day is 30', 'ultimate-store-kit'),
250 'condition' => [
251 'show_new_badge' => 'yes',
252 ],
253 ]
254 );
255 $this->end_controls_tab();
256 $this->end_controls_tabs();
257
258 // $this-> add_control(
259 // 'heading_show_hide_badge',
260 // [
261 // 'label' => esc_html__( 'Badge', 'ultimate-store-kit' ),
262 // 'type' => Controls_Manager::HEADING,
263 // 'separator' => 'before',
264 // ]
265 // );
266
267 $this->end_controls_section();
268 $this->start_controls_section(
269 'section_style_item',
270 [
271 'label' => esc_html__('Items', 'ultimate-store-kit'),
272 'tab' => Controls_Manager::TAB_STYLE,
273 ]
274 );
275 $this->add_group_control(
276 Group_Control_Background::get_type(),
277 [
278 'name' => 'item_background',
279 'label' => esc_html__('Background', 'ultimate-store-kit'),
280 'types' => ['classic', 'gradient'],
281 'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item',
282 ]
283 );
284 $this->add_group_control(
285 Group_Control_Border::get_type(),
286 [
287 'name' => 'item_border',
288 'label' => esc_html__('Border', 'ultimate-store-kit'),
289 'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item',
290 'separator' => 'before',
291 ]
292 );
293 $this->add_control(
294 'item_border_radius',
295 [
296 'label' => esc_html__('Border Radius', 'ultimate-store-kit'),
297 'type' => Controls_Manager::DIMENSIONS,
298 'size_units' => ['px', '%', 'em'],
299 'selectors' => [
300 '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
301 ],
302 ]
303 );
304 $this->add_control(
305 'item_padding',
306 [
307 'label' => esc_html__('Padding', 'ultimate-store-kit'),
308 'type' => Controls_Manager::DIMENSIONS,
309 'size_units' => ['px', '%', 'em'],
310 'selectors' => [
311 '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
312 ],
313 ]
314 );
315
316 $this->add_group_control(
317 Group_Control_Box_Shadow::get_type(),
318 [
319 'name' => 'item_shadow',
320 'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item',
321 ]
322 );
323 $this->end_controls_section();
324
325 $this->start_controls_section(
326 'section_style_image',
327 [
328 'label' => esc_html__('Image', 'ultimate-store-kit'),
329 'tab' => Controls_Manager::TAB_STYLE,
330 'condition' => [
331 'show_image' => 'yes',
332 ],
333 ]
334 );
335
336 $this->add_group_control(
337 Group_Control_Border::get_type(),
338 [
339 'name' => 'image_border',
340 'label' => esc_html__('Image Border', 'ultimate-store-kit'),
341 'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap',
342 ]
343 );
344
345 $this->add_responsive_control(
346 'image_border_radius',
347 [
348 'label' => esc_html__('Border Radius', 'ultimate-store-kit'),
349 'type' => Controls_Manager::DIMENSIONS,
350 'size_units' => ['px', '%'],
351 'selectors' => [
352 '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
353 ],
354 ]
355 );
356
357 $this->add_group_control(
358 Group_Control_Box_Shadow::get_type(),
359 [
360 'name' => 'image_shadow',
361 'exclude' => [
362 'shadow_position',
363 ],
364 'selector' => '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap',
365 ]
366 );
367
368 $this->add_responsive_control(
369 'item_image_size',
370 [
371 'label' => esc_html__('Image Size', 'ultimate-store-kit'),
372 'type' => Controls_Manager::SLIDER,
373 'size_units' => ['px', '%'],
374 'range' => [
375 'px' => [
376 'min' => 50,
377 'max' => 500,
378 ],
379 '%' => [
380 'min' => 0,
381 'max' => 100,
382 ],
383 ],
384 'selectors' => [
385 '{{WRAPPER}} .ultimate-store-kit .usk-list-wrap .usk-item .usk-item-box .usk-image-wrap' => 'width: {{SIZE}}{{UNIT}};',
386 ],
387 ]
388 );
389
390 $this->end_controls_section();
391 $this->register_global_controls_title();
392 $this->register_global_controls_price();
393 $this->register_global_controls_rating();
394 $this->register_global_controls_badge();
395 }
396
397 public function render_header() {
398 ?>
399 <div class="ultimate-store-kit">
400 <div class="usk-product-list">
401 <div class="usk-list-wrap usk-flex usk-flex-column">
402 <?php
403 }
404 public function render_footer() {
405 ?>
406 </div>
407 </div>
408 </div>
409 <?php
410 }
411 public function render_image() {
412 $settings = $this->get_settings_for_display();
413 global $product;
414 ?>
415 <div class="usk-image-wrap usk-flex">
416 <a href="<?php echo esc_url($product->get_permalink()); ?>">
417 <img class="img image-default" src="<?php echo esc_url(wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size'])); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
418 </a>
419 </div>
420 <?php
421 }
422 public function print_price_output($output) {
423 $tags = [
424 'del' => ['aria-hidden' => []],
425 'span' => ['class' => []],
426 'bdi' => [],
427 'ins' => [],
428 ];
429
430 if (isset($output)) {
431 echo wp_kses($output, $tags);
432 }
433 }
434 public function render_loop_item() {
435 $settings = $this->get_settings_for_display();
436 $this->query_product();
437 $wp_query = $this->get_query();
438 if ($wp_query) {
439 while ($wp_query->have_posts()) : $wp_query->the_post();
440 global $product;
441 $average = $product->get_average_rating();
442 $rating_count = $product->get_rating_count();
443 ?>
444 <div class="usk-item">
445 <div class="usk-item-box usk-flex usk-flex-middle">
446 <?php
447 if ($settings['show_image']) :
448 $this->render_image();
449 endif;
450 ?>
451 <div class="usk-content usk-flex usk-flex-column usk-flex-center">
452 <?php
453 if ($settings['show_title']) :
454 printf(
455 '<%1$s class="title"><a href="%2$s" class="usk-title">%3$s</a></%1$s>',
456 esc_attr( Utils::get_valid_html_tag( $settings['title_tags'] ) ),
457 esc_url( $product->get_permalink() ),
458 esc_html( $product->get_title() )
459 );
460 endif; ?>
461 <?php if ($settings['show_rating']) : ?>
462 <div class="usk-rating">
463 <?php echo wp_kses_post($this->register_global_template_wc_rating($average, $rating_count)); ?>
464 </div>
465 <?php endif; ?>
466 <?php if ('yes' == $settings['show_price']) : ?>
467 <div class="usk-price usk-flex usk-flex-middle">
468 <?php $this->print_price_output($product->get_price_html()); ?>
469 </div>
470 <?php endif; ?>
471
472 <?php if ( 'yes' == $settings['show_sale_badge'] || 'yes' == $settings['show_discount_badge'] || 'yes' == $settings['show_stock_status'] || 'yes' == $settings['show_trending_badge'] || 'yes' == $settings['show_new_badge'] ) : ?>
473 <div class="usk-badge-label-wrapper">
474 <div class="usk-badge-label-content usk-flex">
475 <?php $this->register_global_template_badge_label($settings); ?>
476 </div>
477 </div>
478 <?php endif; ?>
479 </div>
480
481 </div>
482 </div>
483 <?php endwhile; ?>
484 <?php
485 wp_reset_postdata();
486 } else {
487 echo '<div class="usk-alert-warning" usk-alert>' . esc_html__('Ops! There no product to display.', 'ultimate-store-kit') . '</div>';
488 }
489 }
490
491 public function render() {
492 $this->render_header();
493 $this->render_loop_item();
494 $this->render_footer();
495 }
496
497 public function query_product() {
498 $default = $this->getGroupControlQueryArgs();
499 if (!isset($default['__use_global_query'])) {
500 $default['post_type'] = 'product';
501 unset($default['p']);
502 }
503 $this->_query = $this->build_query_from_args($default);
504 }
505 }
506