PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.1
ShopBuilder – WooCommerce Builder For Elementor v1.0.1
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 / Elementor / Render / Render.php

Render.php in ShopBuilder – WooCommerce Builder For Elementor 1.0.1, at app/Elementor/Render/Render.php

858 lines 25.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor Render Class.
4 *
5 * This class contains render logics & output.
6 *
7 * @package RadiusTheme\SB
8 */
9
10 namespace RadiusTheme\SB\Elementor\Render;
11
12 use RadiusTheme\SB\Helpers\BuilderFns;
13 use WP_Query;
14 use Elementor\Icons_Manager;
15 use RadiusTheme\SB\Helpers\Fns;
16 use RadiusTheme\SB\Models\QueryArgs;
17 use RadiusTheme\SB\Traits\SingletonTrait;
18 use RadiusTheme\SB\Traits\ActionBtnTraits;
19 use RadiusTheme\SB\Elementor\Helper\RenderHelpers;
20
21 // Do not allow directly accessing this file.
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit( 'This script cannot be accessed directly.' );
24 }
25
26 /**
27 * Elementor Render Class.
28 */
29 class Render {
30 /**
31 * Singleton Trait.
32 */
33 use SingletonTrait;
34
35 /**
36 * Action button trait.
37 */
38 use ActionBtnTraits;
39
40 /**
41 * HTML.
42 *
43 * @var string
44 */
45 private $html = null;
46
47 /**
48 * Settings array
49 *
50 * @var array
51 */
52 public $get_settings;
53
54 /**
55 * Get elementor settings.
56 *
57 * @return array
58 */
59 public function get_settings_for_display() {
60 return $this->get_settings;
61 }
62
63 /**
64 * Container Wrapper HTML.
65 *
66 * @param string $content The content.
67 * @param array $settings Settings.
68 * @param string $class Class.
69 * @param bool $fullwidth Fullwidth check.
70 *
71 * @return string
72 */
73 public function container( $content, $settings, $class = '', $fullwidth = false ) {
74 $layout_id = 'rtsb-container-' . absint( wp_rand() );
75 $container_attr = null;
76 $cart_txt_class = '';
77 $container_class = 'rtsb-elementor-container products rtsb-pos-r ' . esc_attr( $class );
78
79 $metas = RenderHelpers::meta_dataset( $settings );
80
81 $layout = $metas['layout'];
82 $animation = $metas['hover_animation'];
83
84 $is_cat = preg_match( '/category/', $layout );
85 $is_carousel = preg_match( '/slider/', $layout );
86
87 if ( ! $is_cat ) {
88 $cart_txt_class = $metas['show_cart_text'] ? ' has-cart-text' : ' no-cart-text';
89 }
90
91 if ( $is_carousel ) {
92 $fullwidth = true;
93 }
94
95 $badge_class = [
96 'position' => $metas['badge_position'],
97 'alignment' => $metas['badge_alignment'],
98 ];
99
100 if ( ! in_array( $layout, array_keys( Fns::free_layouts() ), true ) ) {
101 $layout = RenderHelpers::set_default_layout( $layout );
102 }
103
104 $d_col = 0 === $metas['d_cols'] ? RenderHelpers::default_columns( $layout ) : $metas['d_cols'];
105 $t_col = 0 === $metas['t_cols'] ? 2 : $metas['t_cols'];
106 $m_col = 0 === $metas['m_cols'] ? 1 : $metas['m_cols'];
107
108 if ( $fullwidth ) {
109 $d_col = 12;
110 $t_col = 12;
111 $m_col = 12;
112 }
113
114 $pagination_attr = ( $is_carousel || $is_cat ? '' : RenderHelpers::pagination_data( $settings ) );
115
116 if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) {
117 $container_class .= ' no-clear-btn';
118 }
119
120 $container_attr .= ' data-layout="' . esc_attr( $layout ) . '" data-desktop-col="' . absint( $d_col ) . '" data-tab-col="' . absint( $t_col ) . '" data-mobile-col="' . absint( $m_col ) . '" ' . $pagination_attr;
121 $container_class .= ' badge-' . esc_attr( $badge_class['position'] ) . ' badge-' . esc_attr( $badge_class['alignment'] ) . esc_attr( $cart_txt_class ) . ' img-hover-' . esc_attr( $animation ) . ' excerpt-' . esc_attr( $metas['cat_excerpt_position'] );
122
123 if ( $metas['show_overlay'] ) {
124 $container_class .= ' has-overlay';
125 }
126
127 $this->html = '<div class="' . esc_attr( $container_class ) . '" id="' . esc_attr( $layout_id ) . '" ' . $container_attr . '>';
128
129 if( ! empty( $settings['query_products'] ) && count( $settings['query_products'] ) && 'yes' === $settings['show_section_title'] ){
130 $this->html .='<div class="rtsb-section-title-wrapper">';
131 $this->html .='<'.esc_attr( $settings['section_title_tag']).' class="rtsb-section-title" >';
132 $this->html .=esc_html($settings['section_title_text']);
133 $this->html .='</'.esc_attr( $settings['section_title_tag']).'>';
134 $this->html .='</div>';
135 }
136
137 $this->html .= $content;
138
139 $this->html .= '</div><!-- .rtsb-elementor-container -->';
140
141 // Action button icon reset.
142 $this->action_button_icon_set_default();
143
144 $script_generator = [];
145 $script_generator['layout'] = $layout_id;
146 $script_generator['rand'] = absint( wp_rand() );
147 $script_generator['isCarousel'] = $is_carousel;
148
149 add_action(
150 'wp_footer',
151 static function () use ( $script_generator ) {
152 RenderHelpers::register_scripts( $script_generator );
153 }
154 );
155
156 return $this->html;
157 }
158
159 /**
160 * Row Wrapper HTML.
161 *
162 * @param string $content The content.
163 * @param array $settings Settings.
164 *
165 * @return string
166 */
167 public function row( $content, $settings ) {
168 $masonry_class = null;
169 $loader_class = ' rtsb-pre-loader';
170
171 $layout = $settings['layout'];
172 $grid_type = $settings['grid_type'];
173 $is_carousel = preg_match( '/slider/', $layout );
174
175 if ( 'even' === $grid_type ) {
176 $masonry_class = ' rtsb-even';
177 } elseif ( 'masonry' === $grid_type ) {
178 $masonry_class = ' rtsb-masonry';
179 }
180
181 if ( ! rtsb()->has_pro() || $is_carousel ) {
182 $masonry_class = ' rtsb-even';
183 }
184
185 $this->html = '<div data-title="' . esc_html__( 'Loading ...', 'shopbuilder' ) . '" class="rtsb-row rtsb-content-loader element-loading ' . esc_attr( 'rtsb-'.$layout . $masonry_class . $loader_class ) . '">';
186
187 if ( $is_carousel ) {
188 $slider_data = RenderHelpers::slider_data( $settings );
189
190 $this->html .= '<div class="rtsb-col-xs-12 ' . esc_attr( $slider_data['class'] ) . '" ' . $slider_data['data'] . '>';
191 $this->html .= '<div class="swiper-wrapper">';
192 }
193
194 $this->html .= $content;
195
196 if ( $is_carousel ) {
197 $this->html .= '</div><!-- .swiper-wrapper -->';
198
199 $left_icon = $settings['left_arrow_icon'];
200 $right_icon = $settings['right_arrow_icon'];
201
202 if ( ! empty( $settings['slider_nav'] ) ) {
203 $this->html .=
204 '<div class="swiper-nav">
205 <div class="swiper-arrow swiper-button-next">
206 ' . Fns::icons_manager( $right_icon ) . '
207 </div>
208 <div class="swiper-arrow swiper-button-prev">
209 ' . Fns::icons_manager( $left_icon ) . '
210 </div>
211 </div>';
212 }
213
214 $this->html .= ! empty( $settings['slider_dot'] ) ? '<div class="swiper-pagination rtsb-pos-s"></div>' : '';
215
216 $this->html .= '</div><!-- .rtsb-carousel-slider -->';
217 }
218
219 $this->html .= RenderHelpers::pre_loader( $layout );
220
221 $this->html .= '</div><!-- .rtsb-row -->';
222
223 return $this->html;
224 }
225
226 /**
227 * Product loop.
228 *
229 * @param object $query The query.
230 * @param array $settings Settings.
231 * @param string $template Template.
232 *
233 * @return string|null
234 */
235 public function product_loop( $query, $settings, $template ) {
236 $html = null;
237
238 if ( empty( $query ) ) {
239 return null;
240 }
241
242 while ( $query->have_posts() ) {
243 $query->the_post();
244
245 // Loop arg.
246 $arg = $this->arg_dataset( $settings, get_the_ID(), $settings['lazy_load'] );
247
248 // Get template.
249 $html .= Fns::load_template( $template . $settings['layout'], $arg, true );
250 }
251
252 return $html;
253 }
254
255 /**
256 * Product loop.
257 *
258 * @param object $query The query.
259 * @param array $settings Settings.
260 * @param string $template Template.
261 * @param bool $is_single Single category.
262 *
263 * @return string|null
264 */
265 public function category_loop( $query, $settings, $template, $is_single = false ) {
266 $html = null;
267 $term_link = null;
268
269 if ( $is_single ) {
270 // Loop arg.
271 $arg = $this->cat_arg_dataset( $settings, $query, true );
272
273 // Get template.
274 $html .= Fns::load_template( $template . $settings['layout'], $arg, true );
275 } else {
276 foreach ( $query as $term ) {
277 // Loop arg.
278 $arg = $this->cat_arg_dataset( $settings, $term );
279
280 // Get template.
281 $html .= Fns::load_template( $template . $settings['layout'], $arg, true );
282 }
283 }
284
285 return $html;
286 }
287
288 /**
289 * Render Product View.
290 *
291 * @param string $template Template name.
292 * @param array $settings Control settings.
293 *
294 * @return string
295 */
296 public function product_view( $template, $settings ) {
297 $this->get_settings = $settings;
298
299 $metas = RenderHelpers::meta_dataset( $settings );
300 $is_carousel = preg_match( '/slider/', $metas['layout'] );
301 $pagination = $metas['pagination'];
302
303 // Query Args.
304 $args = ( new QueryArgs() )->buildArgs( $metas, 'product', $is_carousel );
305
306 // Query.
307 $product_query = new WP_Query( $args );
308
309 if ( $product_query->have_posts() ) {
310 // Row.
311 $this->row( $this->product_loop( $product_query, $metas, $template ), $metas );
312
313 // Pagination.
314 if ( $pagination ) {
315 $this->html .= RenderHelpers::render_pagination(
316 $product_query,
317 $metas,
318 $settings['posts_limit'],
319 $settings['pagination_per_page']
320 );
321 }
322 } else {
323 $this->html .= '<p>' . esc_html__( 'No products found', 'shopbuilder' ) . '</p>';
324 }
325
326 wp_reset_postdata();
327
328 // Container.
329 $this->container( $this->html, $settings, 'rtsb-products-container', $is_carousel );
330
331 return $this->html;
332 }
333
334
335 /**
336 * Render Product View.
337 *
338 * @param string $template Template name.
339 * @param array $settings Control settings.
340 *
341 * @return string
342 */
343 public function wc_loop_for_product_view( $template, $settings ) {
344 global $wp_query, $post;
345
346 $this->get_settings = $settings;
347
348 $metas = RenderHelpers::meta_dataset( $settings );
349 $pagination = $metas['pagination'];
350
351 $page_type = BuilderFns::builder_type( get_the_ID() );
352 $is_preview = BuilderFns::is_builder_preview() && array_key_exists( $page_type, BuilderFns::builder_page_types() );
353 $posts_per_page = wc_get_default_products_per_row() * wc_get_default_product_rows_per_page();
354
355 if ( $is_preview ) {
356 $main_query = clone $wp_query;
357 $main_post = clone $post;
358
359 $ordering = ( new \WC_Query() )->get_catalog_ordering_args();
360 $wp_query_args = [
361 'post_type' => 'product',
362 'posts_per_page' => $posts_per_page,
363 ];
364
365 if ( ! empty( $ordering['orderby'] ) ) {
366 $wp_query_args['orderby'] = $ordering['orderby'];
367 }
368
369 if ( ! empty( $ordering['order'] ) ) {
370 $wp_query_args['order'] = $ordering['order'];
371 }
372
373 $wp_query = new \WP_Query( $wp_query_args ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
374 wc_set_loop_prop( 'total', $wp_query->found_posts );
375 wc_set_loop_prop( 'total_pages', $wp_query->max_num_pages );
376 }
377
378 // column_per_row.
379 if ( woocommerce_product_loop() ) {
380 if ( wc_get_loop_prop( 'total' ) ) {
381 // Row.
382 $this->row( $this->product_loop( $wp_query, $metas, $template ), $metas );
383 }
384
385 // Pagination.
386 if ( $pagination ) {
387 $this->html .= RenderHelpers::render_pagination(
388 $wp_query,
389 $metas,
390 wc_get_loop_prop( 'total' ),
391 $posts_per_page
392 );
393 }
394 } else {
395 $this->html .= '<p>' . esc_html__( 'No products found', 'shopbuilder' ) . '</p>';
396 }
397
398 if ( $is_preview ) {
399 $wp_query = $main_query;
400 $post = $main_post;
401
402 wp_reset_query();
403 wp_reset_postdata();
404 }
405
406 // Container.
407 $this->container( $this->html, $settings, 'rtsb-products-container' );
408
409 return $this->html;
410 }
411
412 /**
413 * Render Product View.
414 *
415 * @param string $template Template name.
416 * @param array $settings Control settings.
417 *
418 * @return string
419 */
420 public function setup_loop_for_product_view( $template, $settings ) {
421 if ( empty( $settings['query_products'] ) ) {
422 return $this->html;
423 }
424
425 $html = null;
426
427 $metas = RenderHelpers::meta_dataset( $settings );
428
429 foreach ( $settings['query_products'] as $_product ) {
430 $post_object = get_post( $_product->get_id() );
431
432 setup_postdata( $GLOBALS['post'] =& $post_object ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found
433
434 // Loop arg.
435 $arg = $this->arg_dataset( $metas, get_the_ID() );
436 // Get template.
437 $html .= Fns::load_template( $template . $settings['layout'], $arg, true );
438
439 $this->row( $html, $metas );
440 }
441
442 // Container.
443 $this->container( $this->html, $settings, 'rtsb-products-container' );
444
445 wp_reset_postdata();
446
447 return $this->html;
448
449 }
450 /**
451 * Render Category View.
452 *
453 * @param string $template Template name.
454 * @param array $settings Control settings.
455 * @param bool $is_single Single category.
456 *
457 * @return string
458 */
459 public function category_view( $template, $settings, $is_single = false ) {
460 $this->get_settings = $settings;
461
462 $metas = RenderHelpers::meta_dataset( $settings );
463 $taxonomy = $metas['category_source'];
464 $term = $metas['category_term'];
465
466 // Query.
467 if ( $is_single ) {
468 if ( empty( $term ) ) {
469 return '<p>' . esc_html__( 'Please select a category.', 'shopbuilder' ) . '</p>';
470 }
471
472 $category_query = get_term( $term, $taxonomy );
473 } else {
474 // Query Args.
475 $args = ( new QueryArgs() )->buildArgs( $metas, 'category' );
476
477 $category_query = get_terms( $args );
478 }
479
480 if ( ! empty( $category_query ) ) {
481 // Row.
482 $this->row( $this->category_loop( $category_query, $metas, $template, $is_single ), $metas );
483 } else {
484 $this->html .= '<p>' . esc_html__( 'No categories found', 'shopbuilder' ) . '</p>';
485 }
486
487 // Container.
488 $this->container( $this->html, $settings, 'rtsb-categories-container', $is_single );
489
490 return $this->html;
491 }
492
493 /**
494 * Render Category View.
495 *
496 * @param string $template Template name.
497 * @param array $settings Control settings.
498 *
499 * @return string
500 */
501 public function social_share_view( $template, $settings ) {
502 $share_items = [];
503
504 foreach ( $settings['share_platforms'] as $platform ) {
505 $share_items[] = [
506 'share_items' => $platform['share_items'],
507 'share_text' => $platform['share_text'],
508 ];
509 }
510
511 if ( ! empty( $share_items ) && is_array( $share_items ) ) {
512 $arg['p_id'] = get_the_ID();
513 $arg['share_items'] = $share_items;
514 $arg['preset'] = $settings['layout'];
515 $arg['show_icon'] = $settings['show_share_icon'];
516 $this->html = Fns::load_template( $template, $arg, true );
517 } else {
518 $this->html = '<p>' . esc_html__( 'Please select a social sharing platform.', 'shopbuilder' ) . '</p>';
519 }
520
521 return $this->html;
522 }
523
524 /**
525 * Builds an array with meta values.
526 *
527 * @param array $meta Meta values.
528 * @param int $post_id Post ID.
529 * @param bool $lazy_load Lazy Load.
530 * @return array
531 */
532 public function arg_dataset( array $meta, int $post_id, bool $lazy_load = false ) {
533 if ( empty( $meta ) && ! $post_id ) {
534 return [];
535 }
536
537 $arg = [];
538 $_product = wc_get_product( $post_id );
539 $p_type = $_product->get_type();
540
541 $arg['class'] = null;
542 $arg['grid'] = null;
543 $arg['anchor_class'] = null;
544 $arg['hover_img_html'] = null;
545 $arg['s_link'] = [];
546 $arg['add_to_cart'] = '';
547 $arg['p_id'] = $post_id;
548 $arg['p_link'] = get_permalink();
549 $arg['p_sale'] = '';
550 $cart_icon_html = '';
551
552 $layout = $meta['layout'];
553
554 $arg['target'] = '_self';
555 $arg['f_img'] = $meta['f_img'];
556 $arg['items'] = $meta['visibility'];
557 $arg['title_tag'] = $meta['title_tag'];
558 $arg['title_class'] = 'product-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' );
559 $arg['title'] = Fns::text_truncation( get_the_title(), $meta['title_limit_custom'] );
560 $arg['excerpt_limit'] = $meta['excerpt_limit'];
561 $arg['excerpt'] = wpautop( Fns::text_truncation( get_the_excerpt(), $meta['excerpt_limit_custom'] ) );
562 $arg['title_link'] = $meta['title_link'];
563 $arg['image_link'] = $meta['image_link'];
564 $arg['out_of_stock'] = $meta['out_of_stock_badge_text'];
565 $arg['action_btn_preset'] = $meta['btn_preset'];
566 $arg['action_btn_position'] = $meta['btn_position'];
567
568 $is_list = preg_match( '/list/', $layout );
569 $is_carousel = preg_match( '/slider/', $layout );
570
571 $d_col = 0 === $meta['d_cols'] ? RenderHelpers::default_columns( $layout ) : $meta['d_cols'];
572 $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols'];
573 $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols'];
574
575 $d_col = 5 === $d_col ? '24' : round( 12 / $d_col );
576 $t_col = 5 === $t_col ? '24' : round( 12 / $t_col );
577 $m_col = 5 === $m_col ? '24' : round( 12 / $m_col );
578
579 if ( ! $is_carousel ) {
580 $arg['grid'] .= 'rtsb-col-md-' . $d_col . ' rtsb-col-sm-' . $t_col . ' rtsb-col-xs-' . $m_col . ' ';
581 $arg['class'] .= ' ' . ( rtsb()->has_pro() ? $meta['gridType'] : 'even' ) . '-grid-item ';
582 } else {
583 $arg['grid'] .= 'rtsb-slide-item swiper-slide ';
584 }
585
586 $arg['class'] .= 'rtsb-product';
587
588 if ( $is_list ) {
589 $arg['class'] .= ' rtsb-product-list';
590 }
591
592 $arg['class'] .= ' animated fadeIn';
593
594 if ( in_array( 'badges', $meta['visibility'], true ) ) {
595 $arg['p_sale'] = Fns::get_sale_badge(
596 $meta['sale_badge_type'],
597 $meta['sale_badge_text'],
598 $meta['out_of_stock_badge_text']
599 );
600 }
601
602 $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] );
603
604 if ( ! $meta['show_cart_text'] ) {
605 $meta['add_to_cart_text'] = '';
606 }
607
608 if ( in_array( 'add_to_cart', $meta['visibility'], true ) ) {
609 if ( ! empty( $meta['add_to_cart_icon'] ) ) {
610 $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_icon'], 'cart-icon' );
611 }
612
613 if ( ! empty( $meta['add_to_cart_success_icon'] ) ) {
614 $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_success_icon'], 'cart-success-icon' );
615 }
616
617 $cart_icon = '<span class="icon">' . $cart_icon_html . '</span>';
618
619 if ( $_product->is_purchasable() ) {
620 if ( $_product->is_in_stock() ) {
621 // TODO:: Replace add to cart with WC hooks
622 $arg['add_to_cart'] = $this->render_add_to_cart_button(
623 get_permalink(),
624 $post_id,
625 $p_type,
626 $meta['add_to_cart_text'],
627 $cart_icon,
628 $meta['add_to_cart_alignment']
629 );
630 }
631 }
632 }
633
634 if ( in_array( 'quick_view', $meta['visibility'], true ) ) {
635 add_filter( 'rtsb/module/quick_view/button_params', [ $this, 'button_classes' ] );
636 add_filter( 'rtsb/module/quick_view/icon_html', [ $this, 'quick_view_icon' ] );
637 }
638
639 if ( in_array( 'compare', $meta['visibility'], true ) ) {
640 add_filter( 'rtsb/module/compare/button_params', [ $this, 'button_classes' ] );
641 add_filter( 'rtsb/module/compare/icon_html', [ $this, 'compare_icon' ] );
642 }
643
644 if ( in_array( 'wishlist', $meta['visibility'], true ) ) {
645 add_filter( 'rtsb/module/wishlist/button_params', [ $this, 'button_classes' ] );
646 add_filter( 'rtsb/module/wishlist/icon_html', [ $this, 'wishlist_icon' ] );
647 }
648
649 $arg['img_html'] = $meta['f_img'] ? Fns::get_product_image_html(
650 'product',
651 $post_id,
652 $meta['f_img_size'],
653 $meta['default_img_id'],
654 $meta['custom_img_size'],
655 $lazy_load
656 ) : null;
657
658 $gallery_ids = $_product->get_gallery_image_ids();
659
660 if ( $meta['hover_img'] && ! empty( $gallery_ids ) ) {
661 $arg['class'] .= ' rtsb-double-img';
662 $arg['hover_img_html'] = Fns::get_product_image_html(
663 'product',
664 $gallery_ids[0],
665 $meta['f_img_size'],
666 null,
667 $meta['custom_img_size'],
668 $lazy_load,
669 true
670 );
671 }
672
673 $arg['hover_btn_text'] = $meta['hover_btn_text'];
674
675 if ( $meta['show_hover_btn_icon'] && ! empty( $meta['hover_btn_icon'] ) ) {
676 $arg['hover_btn_icon'] = '<span class="icon">' . Fns::icons_manager( $meta['hover_btn_icon'], 'hover-btn-icon' ) . '</span>';
677 }
678
679 return $arg;
680 }
681
682 /**
683 * Builds an array with meta values.
684 *
685 * @param array $meta Meta values.
686 * @param Object $query Category object.
687 * @param bool $fullwidth Fullwidth check.
688 * @param bool $lazy_load Lazy Load.
689 * @return array
690 */
691 public function cat_arg_dataset( $meta, $query = null, $fullwidth = false, $lazy_load = false ) {
692 if ( empty( $meta ) ) {
693 return [];
694 }
695
696 $arg = [];
697
698 $arg['class'] = null;
699 $arg['grid'] = null;
700 $arg['anchor_class'] = null;
701 $arg['p_sale'] = null;
702 $arg['count'] = max( $query->count, 0 );
703 $arg['count_position'] = $meta['count_position'];
704 $arg['excerpt_position'] = $meta['cat_excerpt_position'];
705 $arg['cat_link'] = get_term_link( $query );
706 $arg['target'] = '_self';
707
708 if ( ! empty( $meta['custom_link']['url'] ) ) {
709 $arg['cat_link'] = $meta['custom_link']['url'];
710 $arg['target'] = $meta['custom_link']['is_external'] ? '_blank' : '_self';
711 }
712
713 $title = $query->name;
714 $excerpt = $query->description;
715
716 if ( in_array( 'badges', $meta['visibility'], true ) ) {
717 $arg['p_sale'] = $meta['custom_badge_text'];
718 }
719
720 $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] );
721
722 if ( $arg['count'] >= 0 ) {
723 $prefix = ! empty( $meta['before_count'] ) ? $meta['before_count'] : '';
724 $suffix = ! empty( $meta['after_count'] ) ? $meta['after_count'] : '';
725
726 $arg['count'] = $prefix . $arg['count'] . $suffix;
727 }
728
729 if ( $meta['show_custom_title'] && ! empty( $meta['cat_custom_title'] ) ) {
730 $title = $meta['cat_custom_title'];
731 }
732
733 if ( $meta['show_custom_excerpt'] && ! empty( $meta['cat_custom_excerpt'] ) ) {
734 $excerpt = $meta['cat_custom_excerpt'];
735 }
736
737 $layout = $meta['layout'];
738
739 $arg['c_img'] = $meta['c_img'];
740 $arg['items'] = $meta['visibility'];
741 $arg['title_tag'] = $meta['title_tag'];
742 $arg['title_class'] = 'category-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' );
743 $arg['title'] = Fns::text_truncation( $title, $meta['title_limit_custom'] );
744 $arg['excerpt_limit'] = $meta['excerpt_limit'];
745 $arg['excerpt'] = wpautop( Fns::text_truncation( $excerpt, $meta['excerpt_limit_custom'] ) );
746 $arg['title_link'] = $meta['title_link'];
747 $arg['image_link'] = $meta['image_link'];
748
749 $d_col = 0 === $meta['d_cols'] ? RenderHelpers::default_columns( $layout ) : absint( $meta['d_cols'] );
750 $t_col = 0 === $meta['t_cols'] ? 2 : absint( $meta['t_cols'] );
751 $m_col = 0 === $meta['m_cols'] ? 1 : absint( $meta['m_cols'] );
752
753 $d_col = 5 === $d_col ? '24' : round( 12 / $d_col );
754 $t_col = 5 === $t_col ? '24' : round( 12 / $t_col );
755 $m_col = 5 === $m_col ? '24' : round( 12 / $m_col );
756
757 if ( ! $fullwidth ) {
758 $arg['grid'] .= 'rtsb-col-md-' . $d_col . ' rtsb-col-sm-' . $t_col . ' rtsb-col-xs-' . $m_col . ' ';
759 $arg['class'] .= ' ' . ( rtsb()->has_pro() ? $meta['gridType'] : 'even' ) . '-grid-item ';
760 } else {
761 $arg['grid'] .= 'rtsb-col-xs-12 ';
762 }
763
764 $arg['class'] .= 'rtsb-category-grid';
765
766 $arg['img_html'] = $meta['c_img'] ? Fns::get_product_image_html(
767 'category',
768 $query->term_id,
769 $meta['f_img_size'],
770 $meta['default_img_id'],
771 $meta['custom_img_size'],
772 $lazy_load
773 ) : null;
774
775 if ( $meta['show_custom_image'] && ! empty( $meta['custom_image'] ) ) {
776 $arg['img_html'] = Fns::get_product_image_html(
777 'custom',
778 null,
779 $meta['f_img_size'],
780 $meta['custom_image'],
781 $meta['custom_img_size'],
782 $lazy_load
783 );
784 }
785
786 $arg['excerpt_class'] = 'category-info' . ( 'block' === $meta['count_position'] ? ' block-count' : ' inline-count' ) . ( 'above' === $meta['cat_excerpt_position'] ? ' excerpt-above' : '' ) . ( empty( $arg['excerpt'] ) ? ' no-excerpt' : '' );
787
788 return $arg;
789 }
790
791 /**
792 * Renders add to cart button.
793 *
794 * @param string $link Product link.
795 * @param int $id Product ID.
796 * @param string $type Product type.
797 * @param string $text Custom text.
798 * @param string $icon_html Custom icon.
799 * @param string $alignment Icon alignment.
800 * @return string
801 */
802 public function render_add_to_cart_button( $link, $id, $type, $text, $icon_html, $alignment ) {
803 $content = null;
804 $tooltip_attr = '';
805
806 if ( empty( $text ) ) {
807 $tooltip_attr = ' title="' . esc_attr__( 'Add to Cart', 'shopbuilder' ) . '"';
808
809 if ( 'variable' === $type ) {
810 $tooltip_attr = ' title="' . esc_attr__( 'Select Options', 'shopbuilder' ) . '"';
811 }
812 }
813
814 if ( 'variable' === $type ) {
815 $content .= sprintf(
816 '<div class="rtsb-wc-add-to-cart-wrap">
817 <a href="%1$s" data-quantity="1" class="rtsb-action-btn variable-product tipsy icon-%4$s %5$s" data-product_id="%3$s" rel="nofollow"%6$s>%7$s<span class="text">%2$s</span></a>
818 </div>',
819 esc_url( $link ),
820 esc_html__( 'Select Options', 'shopbuilder' ),
821 absint( $id ),
822 esc_attr( $alignment ),
823 empty( $text ) ? 'no-text' : 'has-text',
824 $tooltip_attr,
825 $icon_html,
826 );
827
828 return $content;
829 }
830
831 $content .= sprintf(
832 '<a href="%1$s?add-to-cart=%2$d" data-quantity="1" class="rtsb-action-btn rtsb-add-to-cart-btn tipsy icon-%6$s %7$s" data-id="%2$d" data-type="%3$s"%8$s>%4$s<span class="text">%5$s</span><span></span></a>',
833 esc_url( $link ),
834 absint( $id ),
835 esc_attr( $type ),
836 $icon_html,
837 esc_html( $text ),
838 esc_attr( $alignment ),
839 empty( $text ) ? 'no-text' : 'has-text',
840 $tooltip_attr
841 );
842
843 return $content;
844 }
845
846 /**
847 * Button classes.
848 *
849 * @param array $params Button params.
850 * @return array
851 */
852 public function button_classes( $params ) {
853 $params['classes'] = array_merge( $params['classes'], [ 'rtsb-action-btn', 'tipsy' ] );
854
855 return $params;
856 }
857 }
858