PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 2.0.2
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v2.0.2
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 / shiny-carousel / widgets / shiny-carousel.php

shiny-carousel.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 2.0.2, at modules/shiny-carousel/widgets/shiny-carousel.php

299 lines 11.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\ShinyCarousel\Widgets;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Background;
9 use Elementor\Group_Control_Typography;
10 use UltimateStoreKit\Base\Module_Base;
11 use UltimateStoreKit\traits\Global_Widget_Controls;
12 use UltimateStoreKit\traits\Global_Widget_Template;
13 use UltimateStoreKit\Includes\Controls\GroupQuery\Group_Control_Query;
14 use WP_Query;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 // Exit if accessed directly
21
22 class Shiny_Carousel extends Module_Base {
23 use Global_Widget_Controls;
24 use Global_Widget_Template;
25 use Group_Control_Query;
26
27 /**
28 * @var \WP_Query
29 */
30 private $_query = null;
31
32 public function get_name() {
33 return 'usk-shiny-carousel';
34 }
35
36 public function get_title() {
37 return esc_html__('Shiny Carousel', 'ultimate-store-kit');
38 }
39
40 public function get_icon() {
41 return 'usk-widget-icon usk-icon-shiny-carousel';
42 }
43
44 public function get_categories() {
45 return ['ultimate-store-kit'];
46 }
47
48 public function get_keywords() {
49 return ['product', 'product-grid', 'table', 'wc'];
50 }
51
52 public function get_script_depends() {
53 return ['micromodal'];
54 }
55
56 public function get_style_depends() {
57 if ($this->usk_is_edit_mode()) {
58 return ['usk-all-styles'];
59 } else {
60 return ['usk-font', 'usk-shiny-carousel'];
61 }
62 }
63
64 // public function get_custom_help_url() {
65 // return 'https://youtu.be/3VkvEpVaNAM';
66 // }
67 public function get_query() {
68 return $this->_query;
69 }
70 protected function register_controls() {
71
72 $this->start_controls_section(
73 'section_woocommerce_layout',
74 [
75 'label' => esc_html__('Layout', 'ultimate-store-kit'),
76 ]
77 );
78
79 $this->add_responsive_control(
80 'columns',
81 [
82 'label' => esc_html__('Columns', 'ultimate-store-kit'),
83 'type' => Controls_Manager::SELECT,
84 'default' => 3,
85 'tablet_default' => 2,
86 'mobile_default' => 1,
87 'options' => [
88 1 => '1',
89 2 => '2',
90 3 => '3',
91 4 => '4',
92 5 => '5',
93 6 => '6',
94 ],
95 ]
96 );
97 $this->add_responsive_control(
98 'items_gap',
99 [
100 'label' => esc_html__('Item Gap', 'ultimate-store-kit'),
101 'type' => Controls_Manager::SLIDER,
102 'default' => [
103 'size' => 30,
104 ],
105 'range' => [
106 'px' => [
107 'min' => 0,
108 'max' => 100,
109 ],
110 ],
111 'tablet_default' => [
112 'size' => 20,
113 ],
114 'mobile_default' => [
115 'size' => 20,
116 ],
117 ]
118 );
119
120 $this->register_global_controls_grid_layout();
121
122 $this->end_controls_section();
123 $this->start_controls_section(
124 'section_post_query_builder',
125 [
126 'label' => __('Query', 'ultimate-store-kit'),
127 'tab' => Controls_Manager::TAB_CONTENT,
128 ]
129 );
130 $this->register_query_builder_controls();
131 $this->register_controls_wc_additional();
132 $this->end_controls_section();
133 // $this->register_global_controls_query();
134 $this->register_global_controls_additional();
135 $this->register_global_controls_carousel_navigation();
136 $this->register_global_controls_carousel_settings();
137 $this->register_global_controls_grid_items();
138 $this->register_global_controls_grid_image();
139 $this->register_global_controls_content();
140 $this->register_global_controls_title();
141 $this->register_global_controls_category();
142 $this->register_global_controls_price();
143 $this->register_global_controls_rating();
144 $this->register_global_controls_badge();
145 $this->register_global_controls_add_to_cart();
146 $this->register_global_controls_action_btn();
147 $this->register_global_controls_navigation_style();
148 }
149
150 public function render_image() {
151 global $product;
152 $tooltip_position = 'left';
153 $settings = $this->get_settings_for_display();
154 $gallery_thumbs = $product->get_gallery_image_ids();
155 $product_image = wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size']);
156 if ($gallery_thumbs) {
157 foreach ($gallery_thumbs as $key => $gallery_thumb) {
158 if ($key == 0) :
159 $gallery_image_link = wp_get_attachment_image_url($gallery_thumb, $settings['image_size']);
160 endif;
161 }
162 } else {
163 $gallery_image_link = wp_get_attachment_image_url(get_post_thumbnail_id(), $settings['image_size']);
164 }
165 ?>
166 <div class="usk-image">
167 <a href="<?php echo esc_url(get_permalink()); ?>">
168 <img class="img image-default" src="<?php echo esc_url($product_image); ?>" alt="<?php echo esc_html(get_the_title()); ?>">
169 <img class="img image-hover" src="<?php echo esc_url($gallery_image_link); ?>" alt="<?php echo esc_html(get_the_title()); ?>">
170 </a>
171 <?php $this->render_add_to_cart(); ?>
172 <div class="usk-shoping">
173 <?php $this->register_global_template_add_to_wishlist($tooltip_position); ?>
174 <?php $this->register_global_template_add_to_compare($tooltip_position); ?>
175 <?php $this->register_global_template_quick_view($product->get_id(), $tooltip_position); ?>
176 </div>
177
178 <div class="usk-badge-label-wrapper">
179 <div class="usk-badge-label-content usk-flex usk-flex-column">
180 <?php $this->register_global_template_badge_label(); ?>
181 </div>
182 </div>
183 </div>
184 <?php
185 }
186 public function render_add_to_cart() {
187 global $product;
188 $settings = $this->get_settings_for_display();
189 if ('yes' == $settings['show_cart']) : ?>
190 <?php if ($product) {
191 $defaults = [
192 'quantity' => 1,
193 'class' => implode(
194 ' ',
195 array_filter(
196 [
197 'usk-button',
198 'product_type_' . $product->get_type(),
199 $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
200 $product->supports('ajax_add_to_cart') && $product->is_purchasable() && $product->is_in_stock() ? 'ajax_add_to_cart' : '',
201 ]
202 )
203 ),
204 'attributes' => [
205 'data-product_id' => $product->get_id(),
206 'data-product_sku' => $product->get_sku(),
207 'aria-label' => $product->add_to_cart_description(),
208 'rel' => 'nofollow',
209 ],
210 ];
211 $args = apply_filters('woocommerce_loop_add_to_cart_args', wp_parse_args($defaults), $product);
212 if (isset($args['attributes']['aria-label'])) {
213 $args['attributes']['aria-label'] = wp_strip_all_tags($args['attributes']['aria-label']);
214 }
215 echo wp_kses_post(apply_filters(
216 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
217 sprintf(
218 '<a href="%s" data-quantity="%s" class="%s" %s>%s <i class="button-icon usk-icon-arrow-right-8"></i></a>',
219 esc_url($product->add_to_cart_url()),
220 esc_attr(isset($args['quantity']) ? $args['quantity'] : 1),
221 esc_attr(isset($args['class']) ? $args['class'] : 'button'),
222 isset($args['attributes']) ? wc_implode_html_attributes($args['attributes']) : '',
223 esc_html($product->add_to_cart_text())
224 ),
225 $product,
226 $args
227 ));
228 }; ?>
229 <?php endif;
230 }
231 public function print_price_output($output) {
232 $tags = [
233 'del' => ['aria-hidden' => []],
234 'span' => ['class' => []],
235 'bdi' => [],
236 'ins' => [],
237 ];
238
239 if (isset($output)) {
240 echo wp_kses($output, $tags);
241 }
242 }
243 public function render_loop_item() {
244 $settings = $this->get_settings_for_display();
245 // $wp_query = $this->register_global_template_query();
246 $this->query_product();
247 $wp_query = $this->get_query();
248
249 if ($wp_query->have_posts()) { ?>
250 <?php while ($wp_query->have_posts()) : $wp_query->the_post();
251 global $product;
252 $rating_count = $product->get_rating_count();
253 $average = $product->get_average_rating();
254 $have_rating = ('yes' === $settings['show_rating']) ? 'usk-have-rating' : '';
255 $categories = str_replace(',', '', wc_get_product_category_list($product->get_id()));
256
257 ?>
258 <div class="swiper-slide usk-item <?php esc_attr_e($have_rating, 'ultimate-store-kit'); ?>">
259 <div class="usk-item-box">
260 <?php $this->render_image(); ?>
261 <div class="usk-content">
262 <div class="usk-content-inner">
263 <?php if ('yes' == $settings['show_category']) : ?>
264 <?php printf('<%1$s class="usk-category">%2$s</%1$s>', esc_attr($settings['category_tags']), wp_kses_post($categories)); ?>
265 <?php endif; ?>
266 <?php if ('yes' == $settings['show_title']) : ?>
267 <?php printf('<a href="%2$s" class="usk-title"><%1$s class="title">%3$s</%1$s></a>', esc_attr($settings['title_tags']), esc_url($product->get_permalink()), esc_html($product->get_title())); ?>
268 <?php endif; ?>
269 <?php if ('yes' == $settings['show_price']) : ?>
270 <div class="usk-price">
271 <?php $this->print_price_output($product->get_price_html()); ?>
272 </div>
273 <?php endif; ?>
274 <?php if ('yes' == $settings['show_rating']) : ?>
275 <div class="usk-rating">
276 <span><?php echo wp_kses_post($this->register_global_template_wc_rating($average, $rating_count)); ?></span>
277 </div>
278 <?php endif; ?>
279 </div>
280 </div>
281 </div>
282 </div>
283 <?php endwhile;
284 wp_reset_postdata();
285 } else {
286 echo '<div class="usk-alert-warning" usk-alert>' . esc_html__('Ops! There no product to display.', 'ultimate-store-kit') . '</div>';
287 }
288 }
289 public function render() {
290 $this->register_global_template_carousel_header();
291 $this->render_loop_item();
292 $this->usk_register_global_template_carousel_footer();
293 }
294 public function query_product() {
295 $default = $this->getGroupControlQueryArgs();
296 $this->_query = new WP_Query($default);
297 }
298 }
299