PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.4
ShopBuilder – WooCommerce Builder For Elementor v3.2.4
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Abstracts / LoopWithProductSlider.php

LoopWithProductSlider.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.4, at app/Abstracts/LoopWithProductSlider.php

471 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main ProductDescription class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Abstracts;
9
10 use RadiusTheme\SB\Helpers\Fns;
11 use RadiusTheme\SB\Traits\ActionBtnTraits;
12 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
13 use RadiusTheme\SB\Elementor\Widgets\Controls\StyleFields;
14 use RadiusTheme\SB\Elementor\Widgets\Controls\SliderSettings;
15 use RadiusTheme\SB\Elementor\Widgets\Controls\ProductsSettings;
16 use RadiusTheme\SB\Elementor\Widgets\Controls\ReviewsStarSettings;
17
18 // Do not allow directly accessing this file.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit( 'This script cannot be accessed directly.' );
21 }
22
23 /**
24 * Product Description class
25 */
26 abstract class LoopWithProductSlider extends ElementorWidgetBase {
27 /**
28 * Action Button Traits.
29 */
30 use ActionBtnTraits;
31
32 /**
33 * Product Loop Settings.
34 *
35 * @var object $loop_settings
36 */
37 public $loop_settings;
38 /**
39 * Product Loop Settings.
40 *
41 * @var object $loop_settings
42 */
43 public $has_slider = true;
44 /**
45 * Product Loop Settings.
46 *
47 * @var object $loop_settings
48 */
49 public $has_title = true;
50 /**
51 * Product Loop Settings.
52 *
53 * @var object $loop_settings
54 */
55 public $has_pagination = false;
56 /**
57 * This function Will overwrite by the main function'
58 *
59 * @return array
60 */
61 abstract public function template_data_arg();
62 /**
63 * Widget Field
64 *
65 * @return array
66 */
67 public function widget_fields() {
68 $this->loop_settings = new ProductsSettings( $this );
69 $slider_control = $this->has_slider ? SliderSettings::slider_controls() : [];
70 $slider_style = $this->has_slider ? SliderSettings::slider_style( $this ) : [];
71 $heading = $this->has_title ? $this->loop_settings->heading_controls() : [];
72 $pagination = $this->has_pagination ? $this->loop_settings->pagination() : [];
73
74 return $this->general_section() +
75 $this->loop_settings->widget_icons() +
76 $slider_control +
77 $heading +
78 $this->loop_settings->image_section() +
79 $this->loop_settings->product_title() +
80 $this->loop_settings->product_price() +
81 $this->loop_settings->flash_sale() +
82 ReviewsStarSettings::widget_fields( $this ) +
83 $this->loop_settings->add_to_cart() +
84 $this->loop_settings->module_button_style() +
85 $slider_style +
86 $pagination +
87 StyleFields::not_found_notice( $this );
88 }
89
90 /**
91 * Widget Field
92 *
93 * @return array
94 */
95 public function general_section() {
96 $fields = $this->loop_settings->general_section();
97 if ( 'rtsb-related-product' === $this->rtsb_base ) {
98 unset( $fields['orderby'] );
99 unset( $fields['order'] );
100 }
101 if ( 'rtsb-products-archive' === $this->rtsb_base ) {
102 unset( $fields['posts_per_page'] );
103 unset( $fields['columns'] );
104 unset( $fields['orderby'] );
105 unset( $fields['order'] );
106 }
107 return $fields;
108 }
109
110 /**
111 * Widget Field.
112 *
113 * @return void
114 */
115 public function script_init() {
116 $handle = Fns::optimized_handle( 'rtsb-public' );
117 wp_dequeue_script( $handle );
118
119 wp_enqueue_script( 'swiper' );
120 wp_enqueue_script( $handle );
121 }
122
123 /**
124 * Product loop start function
125 *
126 * @param string $html html.
127 *
128 * @return string
129 */
130 public function product_loop_start( $html = '' ) {
131 $str = explode( 'products', $html );
132 if ( is_array( $str ) && count( $str ) > 1 ) {
133 $html = $str[0] . ' products swiper-wrapper ' . $str[1];
134 }
135 $controllers = $this->get_settings_for_display();
136
137 $swiper_data = [
138 // Optional parameters.
139 'wrapperClass' => 'products',
140 'slideClass' => 'product',
141 'slidesPerView' => 4,
142 'slidesPerGroup' => 3,
143 'spaceBetween' => 15,
144 'loop' => false,
145 ];
146 $classes = [];
147 if ( ! empty( $controllers['columns'] ) ) {
148 $swiper_data['slidesPerView'] = absint( $controllers['columns'] );
149 $swiper_data['slidesPerGroup'] = absint( $controllers['columns'] );
150 }
151 if ( ! empty( $controllers['space_between'] ) ) {
152 $swiper_data['spaceBetween'] = absint( $controllers['space_between'] );
153 }
154 if ( ! empty( $controllers['loop'] ) ) {
155 $swiper_data['loop'] = boolval( $controllers['loop'] );
156 }
157 if ( ! empty( $controllers['autoplay'] ) ) {
158 $swiper_data['autoplay']['delay'] = absint( $controllers['autoplay_delay'] );
159 $swiper_data['autoplay']['pauseOnMouseEnter'] = boolval( $controllers['pauseon_mouseenter'] );
160 $swiper_data['autoplay']['disableOnInteraction'] = false;
161 }
162 if ( ! empty( $controllers['speed'] ) ) {
163 $swiper_data['speed'] = absint( $controllers['speed'] );
164 }
165 if ( ! empty( $controllers['show_arrows'] ) ) {
166 $swiper_data['navigation'] = [
167 'nextEl' => '.button-right',
168 'prevEl' => '.button-left',
169 ];
170 $classes[] = 'has-navigation';
171 }
172 if ( ! empty( $controllers['show_dots'] ) ) {
173 $swiper_data['pagination'] = [
174 'el' => '.rtsb-slider-pagination',
175 'type' => 'bullets',
176 'clickable' => true,
177 ];
178 $classes[] = 'has-dots';
179 }
180
181 $data = [
182 'template' => 'global/slider-header',
183 'controllers' => $controllers,
184 'swiper_json_data' => wp_json_encode( $swiper_data ),
185 'classes' => $classes,
186 ];
187 $new = Fns::load_template( $data['template'], $data, true );
188 $html = $new . $html;
189 return $html;
190 }
191 /**
192 * Product loop start function
193 *
194 * @param string $html html.
195 *
196 * @return string
197 */
198 public function product_loop_end( $html ) {
199 $controllers = $this->get_settings_for_display();
200 $data = [
201 'template' => 'global/slider-footer',
202 'controllers' => $controllers,
203 'left_arrow' => Fns::icons_manager( $controllers['left_arrow_icon'] ),
204 'right_arrow' => Fns::icons_manager( $controllers['right_arrow_icon'] ),
205 ];
206 $new = Fns::load_template( $data['template'], $data, true );
207 $html = $html . $new;
208 return $html;
209 }
210 /**
211 * Product loop start function
212 *
213 * @param string $classes classes.
214 *
215 * @return string
216 */
217 public function post_class( $classes ) {
218 $classes[] = 'swiper-slide';
219 return $classes;
220 }
221
222 /**
223 * Image Wrapper.
224 *
225 * @return void
226 */
227 public function image_wrapper() {
228 if ( ! RenderHelpers::is_wrapper_needed() ) {
229 return;
230 }
231 ?>
232 <div class="rtsb-image-wrapper">
233 <?php
234 }
235 /**
236 * Image Wrapper.
237 *
238 * @return void
239 */
240 public function div_close() {
241 if ( ! RenderHelpers::is_wrapper_needed() ) {
242 return;
243 }
244 ?>
245 </div>
246 <?php
247 }
248 /**
249 * Image Wrapper.
250 *
251 * @return void
252 */
253 public function product_content_wrapper() {
254 if ( ! RenderHelpers::is_wrapper_needed() ) {
255 return;
256 }
257 ?>
258 <div class="rtsb-product-content">
259 <?php
260 }
261
262 /**
263 * Apply hooks function.
264 *
265 * @return void
266 */
267 public function apply_hooks() {
268 $controllers = $this->get_settings_for_display();
269
270 if ( empty( $controllers['show_rating'] ) ) {
271 remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
272 add_filter( 'woocommerce_product_get_rating_html', '__return_false' );
273 }
274 if ( empty( $controllers['show_flash_sale'] ) ) {
275 add_filter( 'woocommerce_sale_flash', '__return_false' );
276 }
277 if ( ! empty( $controllers['slider_activate'] ) ) {
278 add_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
279 add_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
280 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
281 $this->script_init();
282 }
283
284 if ( class_exists( 'WooProductVariationSwatches' ) ) {
285 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 5 );
286 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 20 );
287 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 8 );
288 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 12 );
289 }
290
291 // Remove Action Button.
292 add_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
293 add_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
294 add_filter( 'rtsb/module/compare/show_button', '__return_false' );
295
296 if ( empty( $controllers['show_quick_checkout'] ) ) {
297 add_filter( 'rtsb/module/quick_checkout/show_button', '__return_false' );
298 }
299 if ( empty( $controllers['show_flash_sale_countdown'] ) ) {
300 add_filter( 'rtsb/module/flash_sale_countdown/show_counter', '__return_false' );
301 }
302
303 // Default Link remove.
304 remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
305 remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
306
307 // Image Wrapper open.
308 add_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
309
310 // Image link.
311 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
312 add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
313 // Image link end.
314
315 // Title Link.
316 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
317 add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
318 // Title Link end.
319
320 // Image Wrapper close.
321 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
322 // Content Wrapper Open.
323 add_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
324 // Content Wrapper Close.
325 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
326
327 if ( $this->is_edit_mode() ) {
328 if ( class_exists( Rtwpvs\Controllers\Hooks::class ) ) {
329 remove_filter( 'woocommerce_ajax_variationX_threshold', [ Rtwpvs\Controllers\Hooks::class, 'ajax_variation_threshold' ], 99 );
330 }
331 add_filter(
332 'woocommerce_ajax_variation_threshold',
333 function () {
334 return 1;
335 },
336 99
337 );
338
339 }
340 }
341 /**
342 * Apply hooks function.
343 *
344 * @return void
345 */
346 public function apply_hooks_set_default() {
347
348 // Default Link re active.
349 add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
350 add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
351
352 // Image Wrapper open.
353 remove_action( 'woocommerce_before_shop_loop_item', [ $this, 'image_wrapper' ], -1 );
354
355 // Image link.
356 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
357 remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
358 // Image link end.
359
360 // Title Link.
361 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_open', 9 );
362 remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 11 );
363 // Title Link End.
364
365 // Image Wrapper close.
366 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'div_close' ], 12 );
367
368 // Content Wrapper Open.
369 remove_action( 'woocommerce_before_shop_loop_item_title', [ $this, 'product_content_wrapper' ], 13 );
370 // Content Wrapper Close.
371 remove_action( 'woocommerce_after_shop_loop_item', [ $this, 'div_close' ], 99 );
372
373 // Remove Action Button.
374 remove_filter( 'rtsb/module/wishlist/show_button', '__return_false' );
375 remove_filter( 'rtsb/module/quick_view/show_button', '__return_false' );
376 remove_filter( 'rtsb/module/compare/show_button', '__return_false' );
377 }
378 /**
379 * Related Product Args function'
380 *
381 * @param [type] $args argument.
382 * @return array
383 */
384 public function products_args( $args ) {
385 $controllers = $this->get_settings_for_display();
386 if ( ! empty( $controllers['posts_per_page'] ) ) {
387 $args['posts_per_page'] = intval( $controllers['posts_per_page'] );
388 }
389 if ( ! empty( $controllers['columns'] ) ) {
390 $args['columns'] = absint( $controllers['columns'] );
391 }
392 if ( ! empty( $controllers['orderby'] ) ) {
393 $args['orderby'] = $controllers['orderby'];
394 }
395 if ( ! empty( $controllers['order'] ) ) {
396 $args['order'] = $controllers['order'];
397 }
398 return $args;
399 }
400
401 /**
402 * Elementor Edit mode script
403 *
404 * @return void
405 */
406 public function editor_script() {
407 if ( ! $this->is_edit_mode() ) {
408 return;
409 }
410 ?>
411 <script>
412 <?php if ( rtsb()->has_pro() ) { ?>
413 if (!'<?php echo esc_attr( Fns::is_optimization_enabled() ); ?>') {
414 setTimeout( function (){
415 window.rtsbCountdownApply();
416 }, 1000 );
417 } else {
418 if (typeof elementorFrontend !== 'undefined') {
419 window.waitForRTSB((RTSB) => {
420 RTSB.modules.get('countdownPro')?.refresh();
421 });
422 }
423 }
424 <?php } ?>
425 </script>
426 <?php
427 }
428
429 /**
430 * Render Function
431 *
432 * @return void
433 */
434 protected function render() {
435 global $product, $post;
436 $data = $this->template_data_arg();
437 if ( empty( $data['template'] ) ) {
438 return;
439 }
440 $_product = $product;
441 $product = Fns::get_product();
442 $controllers = $this->get_settings_for_display();
443
444 $controllers['cart_icon_html'] = Fns::icons_manager( $controllers['cart_icon'] );
445
446 $this->apply_hooks();
447 $this->theme_support();
448
449 $this->action_button_icon_modify();
450
451 $data['controllers'] = $controllers;
452
453 Fns::load_template( $data['template'], $data );
454
455 $this->apply_hooks_set_default();
456 $this->action_button_icon_set_default();
457 $this->theme_support( 'render_reset' );
458
459 $product = $_product; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
460 if ( ! empty( $controllers['slider_activate'] ) ) {
461 remove_filter( 'woocommerce_product_loop_start', [ $this, 'product_loop_start' ] );
462 remove_filter( 'woocommerce_product_loop_end', [ $this, 'product_loop_end' ] );
463 remove_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 10, 1 );
464 $this->editor_slider_script();
465 }
466
467 $this->editor_script();
468 $this->editor_cart_icon_script();
469 }
470 }
471