PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.0.8
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.0.8
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.0.8, at modules/product-list/widgets/product-list.php

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