PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.1
ShopBuilder – WooCommerce Builder For Elementor v1.1.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.1.1, at app/Elementor/Render/Render.php

863 lines 25.4 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 $this->get_settings = $settings;
503 $share_items = [];
504
505 foreach ( $settings['share_platforms'] as $platform ) {
506 $share_items[] = [
507 'share_items' => $platform['share_items'],
508 'share_text' => $platform['share_text'],
509 ];
510 }
511
512 if ( ! empty( $share_items ) && is_array( $share_items ) ) {
513 $arg['p_id'] = get_the_ID();
514 $arg['share_items'] = $share_items;
515 $arg['preset'] = $settings['layout'];
516 $arg['show_icon'] = $settings['show_share_icon'];
517 $arg['raw_settings'] = $this->get_settings_for_display();
518 $this->html = Fns::load_template( $template, $arg, true );
519 } else {
520 $this->html = '<p>' . esc_html__( 'Please select a social sharing platform.', 'shopbuilder' ) . '</p>';
521 }
522
523 return $this->html;
524 }
525
526 /**
527 * Builds an array with meta values.
528 *
529 * @param array $meta Meta values.
530 * @param int $post_id Post ID.
531 * @param bool $lazy_load Lazy Load.
532 * @return array
533 */
534 public function arg_dataset( array $meta, int $post_id, bool $lazy_load = false ) {
535 if ( empty( $meta ) && ! $post_id ) {
536 return [];
537 }
538 global $post;
539
540 $arg = [];
541 $_product = wc_get_product( $post_id );
542 $p_type = $_product->get_type();
543
544 $arg['class'] = null;
545 $arg['grid'] = null;
546 $arg['anchor_class'] = null;
547 $arg['hover_img_html'] = null;
548 $arg['s_link'] = [];
549 $arg['add_to_cart'] = '';
550 $arg['p_id'] = $post_id;
551 $arg['p_link'] = get_permalink();
552 $arg['p_sale'] = '';
553 $arg['raw_settings'] = $this->get_settings_for_display();
554 $cart_icon_html = '';
555
556 $layout = $meta['layout'];
557
558 $arg['target'] = '_self';
559 $arg['f_img'] = $meta['f_img'];
560 $arg['items'] = $meta['visibility'];
561 $arg['title_tag'] = $meta['title_tag'];
562 $arg['title_class'] = 'product-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' );
563 $arg['title'] = Fns::text_truncation( get_the_title(), $meta['title_limit_custom'] );
564 $arg['excerpt_limit'] = $meta['excerpt_limit'];
565 $arg['excerpt'] = wpautop( Fns::text_truncation( do_shortcode( $post->post_excerpt ), $meta['excerpt_limit_custom'] ) );
566 $arg['title_link'] = $meta['title_link'];
567 $arg['image_link'] = $meta['image_link'];
568 $arg['out_of_stock'] = $meta['out_of_stock_badge_text'];
569 $arg['action_btn_preset'] = $meta['btn_preset'];
570 $arg['action_btn_position'] = $meta['btn_position'];
571
572 $is_list = preg_match( '/list/', $layout );
573 $is_carousel = preg_match( '/slider/', $layout );
574
575 $d_col = 0 === $meta['d_cols'] ? RenderHelpers::default_columns( $layout ) : $meta['d_cols'];
576 $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols'];
577 $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols'];
578
579 $d_col = 5 === $d_col ? '24' : round( 12 / $d_col );
580 $t_col = 5 === $t_col ? '24' : round( 12 / $t_col );
581 $m_col = 5 === $m_col ? '24' : round( 12 / $m_col );
582
583 if ( ! $is_carousel ) {
584 $arg['grid'] .= 'rtsb-col-md-' . $d_col . ' rtsb-col-sm-' . $t_col . ' rtsb-col-xs-' . $m_col . ' ';
585 $arg['class'] .= ' even-grid-item ';
586 } else {
587 $arg['grid'] .= 'rtsb-slide-item swiper-slide ';
588 }
589
590 $arg['class'] .= 'rtsb-product';
591
592 if ( $is_list ) {
593 $arg['class'] .= ' rtsb-product-list';
594 }
595
596 $arg['class'] .= ' animated fadeIn';
597
598 if ( in_array( 'badges', $meta['visibility'], true ) ) {
599 $arg['p_sale'] = Fns::get_sale_badge(
600 $meta['sale_badge_type'],
601 $meta['sale_badge_text'],
602 $meta['out_of_stock_badge_text']
603 );
604 }
605
606 $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] );
607
608 if ( ! $meta['show_cart_text'] ) {
609 $meta['add_to_cart_text'] = '';
610 }
611
612 if ( in_array( 'add_to_cart', $meta['visibility'], true ) ) {
613 if ( ! empty( $meta['add_to_cart_icon'] ) ) {
614 $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_icon'], 'cart-icon' );
615 }
616
617 if ( ! empty( $meta['add_to_cart_success_icon'] ) ) {
618 $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_success_icon'], 'cart-success-icon' );
619 }
620
621 $cart_icon = '<span class="icon">' . $cart_icon_html . '</span>';
622
623 if ( $_product->is_purchasable() ) {
624 if ( $_product->is_in_stock() ) {
625 // TODO:: Replace add to cart with WC hooks
626 $arg['add_to_cart'] = $this->render_add_to_cart_button(
627 get_permalink(),
628 $post_id,
629 $p_type,
630 $meta['add_to_cart_text'],
631 $cart_icon,
632 $meta['add_to_cart_alignment']
633 );
634 }
635 }
636 }
637
638 if ( in_array( 'quick_view', $meta['visibility'], true ) ) {
639 add_filter( 'rtsb/module/quick_view/button_params', [ $this, 'button_classes' ] );
640 add_filter( 'rtsb/module/quick_view/icon_html', [ $this, 'quick_view_icon' ] );
641 }
642
643 if ( in_array( 'compare', $meta['visibility'], true ) ) {
644 add_filter( 'rtsb/module/compare/button_params', [ $this, 'button_classes' ] );
645 add_filter( 'rtsb/module/compare/icon_html', [ $this, 'compare_icon' ] );
646 }
647
648 if ( in_array( 'wishlist', $meta['visibility'], true ) ) {
649 add_filter( 'rtsb/module/wishlist/button_params', [ $this, 'button_classes' ] );
650 add_filter( 'rtsb/module/wishlist/icon_html', [ $this, 'wishlist_icon' ] );
651 }
652
653 $arg['img_html'] = $meta['f_img'] ? Fns::get_product_image_html(
654 'product',
655 $post_id,
656 $meta['f_img_size'],
657 $meta['default_img_id'],
658 $meta['custom_img_size'],
659 $lazy_load
660 ) : null;
661
662 $gallery_ids = $_product->get_gallery_image_ids();
663
664 if ( $meta['hover_img'] && ! empty( $gallery_ids ) ) {
665 $arg['class'] .= ' rtsb-double-img';
666 $arg['hover_img_html'] = Fns::get_product_image_html(
667 'product',
668 $gallery_ids[0],
669 $meta['f_img_size'],
670 null,
671 $meta['custom_img_size'],
672 $lazy_load,
673 true
674 );
675 }
676
677 $arg['hover_btn_text'] = $meta['hover_btn_text'];
678
679 if ( $meta['show_hover_btn_icon'] && ! empty( $meta['hover_btn_icon'] ) ) {
680 $arg['hover_btn_icon'] = '<span class="icon">' . Fns::icons_manager( $meta['hover_btn_icon'], 'hover-btn-icon' ) . '</span>';
681 }
682
683 return $arg;
684 }
685
686 /**
687 * Builds an array with meta values.
688 *
689 * @param array $meta Meta values.
690 * @param Object $query Category object.
691 * @param bool $fullwidth Fullwidth check.
692 * @param bool $lazy_load Lazy Load.
693 * @return array
694 */
695 public function cat_arg_dataset( $meta, $query = null, $fullwidth = false, $lazy_load = false ) {
696 if ( empty( $meta ) ) {
697 return [];
698 }
699
700 $arg = [];
701
702 $arg['class'] = null;
703 $arg['grid'] = null;
704 $arg['anchor_class'] = null;
705 $arg['p_sale'] = null;
706 $arg['count'] = max( $query->count, 0 );
707 $arg['count_position'] = $meta['count_position'];
708 $arg['excerpt_position'] = $meta['cat_excerpt_position'];
709 $arg['cat_link'] = get_term_link( $query );
710 $arg['target'] = '_self';
711 $arg['raw_settings'] = $this->get_settings_for_display();
712
713 if ( ! empty( $meta['custom_link']['url'] ) ) {
714 $arg['cat_link'] = $meta['custom_link']['url'];
715 $arg['target'] = $meta['custom_link']['is_external'] ? '_blank' : '_self';
716 }
717
718 $title = $query->name;
719 $excerpt = $query->description;
720
721 if ( in_array( 'badges', $meta['visibility'], true ) ) {
722 $arg['p_sale'] = $meta['custom_badge_text'];
723 }
724
725 $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] );
726
727 if ( $arg['count'] >= 0 ) {
728 $prefix = ! empty( $meta['before_count'] ) ? $meta['before_count'] : '';
729 $suffix = ! empty( $meta['after_count'] ) ? $meta['after_count'] : '';
730
731 $arg['count'] = $prefix . $arg['count'] . $suffix;
732 }
733
734 if ( $meta['show_custom_title'] && ! empty( $meta['cat_custom_title'] ) ) {
735 $title = $meta['cat_custom_title'];
736 }
737
738 if ( $meta['show_custom_excerpt'] && ! empty( $meta['cat_custom_excerpt'] ) ) {
739 $excerpt = $meta['cat_custom_excerpt'];
740 }
741
742 $layout = $meta['layout'];
743
744 $arg['c_img'] = $meta['c_img'];
745 $arg['items'] = $meta['visibility'];
746 $arg['title_tag'] = $meta['title_tag'];
747 $arg['title_class'] = 'category-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' );
748 $arg['title'] = Fns::text_truncation( $title, $meta['title_limit_custom'] );
749 $arg['excerpt_limit'] = $meta['excerpt_limit'];
750 $arg['excerpt'] = wpautop( Fns::text_truncation( $excerpt, $meta['excerpt_limit_custom'] ) );
751 $arg['title_link'] = $meta['title_link'];
752 $arg['image_link'] = $meta['image_link'];
753
754 $d_col = 0 === $meta['d_cols'] ? RenderHelpers::default_columns( $layout ) : absint( $meta['d_cols'] );
755 $t_col = 0 === $meta['t_cols'] ? 2 : absint( $meta['t_cols'] );
756 $m_col = 0 === $meta['m_cols'] ? 1 : absint( $meta['m_cols'] );
757
758 $d_col = 5 === $d_col ? '24' : round( 12 / $d_col );
759 $t_col = 5 === $t_col ? '24' : round( 12 / $t_col );
760 $m_col = 5 === $m_col ? '24' : round( 12 / $m_col );
761
762 if ( ! $fullwidth ) {
763 $arg['grid'] .= 'rtsb-col-md-' . $d_col . ' rtsb-col-sm-' . $t_col . ' rtsb-col-xs-' . $m_col . ' ';
764 $arg['class'] .= ' even-grid-item ';
765 } else {
766 $arg['grid'] .= 'rtsb-col-xs-12 ';
767 }
768
769 $arg['class'] .= 'rtsb-category-grid';
770
771 $arg['img_html'] = $meta['c_img'] ? Fns::get_product_image_html(
772 'category',
773 $query->term_id,
774 $meta['f_img_size'],
775 $meta['default_img_id'],
776 $meta['custom_img_size'],
777 $lazy_load
778 ) : null;
779
780 if ( $meta['show_custom_image'] && ! empty( $meta['custom_image'] ) ) {
781 $arg['img_html'] = Fns::get_product_image_html(
782 'custom',
783 null,
784 $meta['f_img_size'],
785 $meta['custom_image'],
786 $meta['custom_img_size'],
787 $lazy_load
788 );
789 }
790
791 $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' : '' );
792
793 return $arg;
794 }
795
796 /**
797 * Renders add to cart button.
798 *
799 * @param string $link Product link.
800 * @param int $id Product ID.
801 * @param string $type Product type.
802 * @param string $text Custom text.
803 * @param string $icon_html Custom icon.
804 * @param string $alignment Icon alignment.
805 * @return string
806 */
807 public function render_add_to_cart_button( $link, $id, $type, $text, $icon_html, $alignment ) {
808 $content = null;
809 $tooltip_attr = '';
810
811 if ( empty( $text ) ) {
812 $tooltip_attr = ' title="' . esc_attr__( 'Add to Cart', 'shopbuilder' ) . '"';
813
814 if ( 'variable' === $type ) {
815 $tooltip_attr = ' title="' . esc_attr__( 'Select Options', 'shopbuilder' ) . '"';
816 }
817 }
818
819 if ( 'variable' === $type ) {
820 $content .= sprintf(
821 '<div class="rtsb-wc-add-to-cart-wrap">
822 <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>
823 </div>',
824 esc_url( $link ),
825 esc_html__( 'Select Options', 'shopbuilder' ),
826 absint( $id ),
827 esc_attr( $alignment ),
828 empty( $text ) ? 'no-text' : 'has-text',
829 $tooltip_attr,
830 $icon_html,
831 );
832
833 return $content;
834 }
835
836 $content .= sprintf(
837 '<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>',
838 esc_url( $link ),
839 absint( $id ),
840 esc_attr( $type ),
841 $icon_html,
842 esc_html( $text ),
843 esc_attr( $alignment ),
844 empty( $text ) ? 'no-text' : 'has-text',
845 $tooltip_attr
846 );
847
848 return $content;
849 }
850
851 /**
852 * Button classes.
853 *
854 * @param array $params Button params.
855 * @return array
856 */
857 public function button_classes( $params ) {
858 $params['classes'] = array_merge( $params['classes'], [ 'rtsb-action-btn', 'tipsy' ] );
859
860 return $params;
861 }
862 }
863