! empty( $meta['layout'] ) ? $meta['layout'] : 'layout1', 'd_cols' => ! empty( $meta['cols'] ) ? $meta['cols'] : 0, 't_cols' => ! empty( $meta['cols_tablet'] ) ? $meta['cols_tablet'] : 2, 'm_cols' => ! empty( $meta['cols_mobile'] ) ? $meta['cols_mobile'] : 1, 'grid_type' => ! empty( $meta['grid_style'] ) ? $meta['grid_style'] : 'even', // Query. 'post_in' => ! empty( $meta['include_posts'] ) && is_array( $meta['include_posts'] ) ? $meta['include_posts'] : [], 'post_not_in' => ! empty( $meta['exclude_posts'] ) && is_array( $meta['exclude_posts'] ) ? $meta['exclude_posts'] : [], 'limit' => ( empty( $meta['posts_limit'] ) || '-1' === $meta['posts_limit'] ) ? 10000000 : $meta['posts_limit'], 'offset' => ! empty( $meta['posts_offset'] ) ? $meta['posts_offset'] : 0, 'order_by' => ! empty( $meta['posts_order_by'] ) ? $meta['posts_order_by'] : 'date', 'order' => ! empty( $meta['posts_order'] ) ? $meta['posts_order'] : 'DESC', 'author_in' => ! empty( $meta['filter_author'] ) && is_array( $meta['filter_author'] ) ? $meta['filter_author'] : [], 'display_by' => ! empty( $meta['products_filter'] ) ? $meta['products_filter'] : 'date', 'categories' => ! empty( $meta['filter_categories'] ) && is_array( $meta['filter_categories'] ) ? $meta['filter_categories'] : [], 'tags' => ! empty( $meta['filter_tags'] ) && is_array( $meta['filter_tags'] ) ? $meta['filter_tags'] : [], 'attributes' => ! empty( $meta['filter_attributes'] ) && is_array( $meta['filter_attributes'] ) ? $meta['filter_attributes'] : [], 'relation' => ! empty( $meta['tax_relation'] ) ? $meta['tax_relation'] : 'OR', 'category_source' => ! empty( $meta['select_source'] ) ? $meta['select_source'] : 'product_cat', 'category_term' => ! empty( $meta['select_cat'] ) ? $meta['select_cat'] : null, 'display_cat_by' => ! empty( $meta['display_cat_by'] ) ? $meta['display_cat_by'] : null, 'include_cats' => ! empty( $meta['include_cats'] ) && is_array( $meta['include_cats'] ) ? $meta['include_cats'] : [], 'exclude_cats' => ! empty( $meta['exclude_cats'] ) && is_array( $meta['exclude_cats'] ) ? $meta['exclude_cats'] : [], 'select_parent_cat' => ! empty( $meta['select_parent_cat'] ) ? $meta['select_parent_cat'] : null, 'select_cats' => ! empty( $meta['select_cats'] ) && is_array( $meta['select_cats'] ) ? $meta['select_cats'] : [], 'select_cat_ids' => ! empty( $meta['include_cat_ids'] ) ? $meta['include_cat_ids'] : '', 'cats_limit' => ( empty( $meta['cats_limit'] ) || '-1' === $meta['cats_limit'] ) ? 10000000 : $meta['cats_limit'], 'show_empty' => ! empty( $meta['show_empty'] ), 'show_uncategorized' => ! empty( $meta['show_uncategorized'] ), 'show_subcats' => ! empty( $meta['show_subcats'] ), 'show_top_level_cats' => ! empty( $meta['show_top_level_cats'] ), 'cats_order_by' => ! empty( $meta['cats_order_by'] ) ? $meta['cats_order_by'] : 'name', 'cats_order' => ! empty( $meta['cats_order'] ) ? $meta['cats_order'] : 'DESC', // Pagination. 'pagination' => ! empty( $meta['show_pagination'] ), 'posts_loading_type' => ! empty( $meta['pagination_type'] ) ? $meta['pagination_type'] : 'pagination', 'posts_per_page' => ! empty( $meta['pagination_per_page'] ) ? $meta['pagination_per_page'] : '', // Image. 'f_img' => ! empty( $meta['show_featured_image'] ), 'c_img' => ! empty( $meta['show_cat_image'] ), 'hover_img' => ! empty( $meta['show_hover_image'] ), 'f_img_size' => ! empty( $meta['image'] ) ? $meta['image'] : 'medium', 'custom_img_size' => ! empty( $c_image_size ) && is_array( $c_image_size ) ? $c_image_size : [], 'default_img_id' => ! empty( $meta['default_preview_image']['id'] ) ? $meta['default_preview_image']['id'] : null, 'show_overlay' => ! empty( $meta['show_overlay'] ), 'hover_animation' => ! empty( $meta['image_hover_animation'] ) ? $meta['image_hover_animation'] : 'none', 'show_custom_image' => ! empty( $meta['show_custom_image'] ), 'custom_image' => ! empty( $meta['custom_image']['id'] ) ? $meta['custom_image']['id'] : null, // Visibility. 'visibility' => ! empty( self::content_visibility( $meta ) ) ? self::content_visibility( $meta ) : [], // Action Buttons. 'btn_preset' => ! empty( $meta['action_btn_preset'] ) ? $meta['action_btn_preset'] : 'preset1', 'btn_position' => ! empty( $meta['action_btn_position'] ) ? $meta['action_btn_position'] : 'above', // Product Title. 'title_tag' => ! empty( $meta['title_tag'] ) ? $meta['title_tag'] : 'h3', 'title_hover' => ! empty( $meta['title_hover'] ), 'title_limit' => ! empty( $meta['title_limit'] ) ? $meta['title_limit'] : 'default', 'title_limit_custom' => ! empty( $meta['title_limit_custom'] ) ? $meta['title_limit_custom'] : null, 'show_custom_title' => ! empty( $meta['show_custom_title'] ), 'cat_custom_title' => ! empty( $meta['custom_title'] ) ? $meta['custom_title'] : '', // Short Description. 'show_custom_excerpt' => ! empty( $meta['show_custom_description'] ), 'cat_custom_excerpt' => ! empty( $meta['custom_description'] ) ? $meta['custom_description'] : '', 'cat_excerpt_position' => ! empty( $meta['excerpt_position'] ) ? $meta['excerpt_position'] : 'below', 'excerpt_limit' => ! empty( $meta['excerpt_limit'] ) ? $meta['excerpt_limit'] : 'default', 'excerpt_limit_custom' => ! empty( $meta['excerpt_limit_custom'] ) ? $meta['excerpt_limit_custom'] : 200, // Count. 'count_position' => ! empty( $meta['count_display_type'] ) ? $meta['count_display_type'] : 'flex', 'before_count' => ! empty( $meta['before_count'] ) ? $meta['before_count'] : '', 'after_count' => ! empty( $meta['after_count'] ) ? $meta['after_count'] : '', // Add to cart. 'show_cart_icon' => ! empty( $meta['show_cart_icon'] ), 'show_cart_text' => ! empty( $meta['show_cart_text'] ), 'add_to_cart_icon' => ! empty( $meta['add_to_cart_icon'] ) ? $meta['add_to_cart_icon'] : [], 'add_to_cart_success_icon' => ! empty( $meta['add_to_cart_success_icon'] ) ? $meta['add_to_cart_success_icon'] : [], 'add_to_cart_text' => ! empty( $meta['add_to_cart_text'] ) ? $meta['add_to_cart_text'] : esc_html__( 'Add to Cart', 'shopbuilder' ), 'add_to_cart_alignment' => ! empty( $meta['cart_icon_alignment'] ) ? $meta['cart_icon_alignment'] : 'left', // Badges. 'sale_badge_type' => ! empty( $meta['sale_badges_type'] ) ? $meta['sale_badges_type'] : 'percentage', 'sale_badge_text' => ! empty( $meta['sale_badges_text'] ) ? $meta['sale_badges_text'] : esc_html__( 'Sale', 'shopbuilder' ), 'custom_badge_text' => ! empty( $meta['custom_badge_text'] ) ? $meta['custom_badge_text'] : esc_html__( 'Sale', 'shopbuilder' ), 'out_of_stock_badge_text' => ! empty( $meta['stock_badges_text'] ) ? $meta['stock_badges_text'] : esc_html__( 'Out of Stock', 'shopbuilder' ), 'badge_position' => ! empty( $meta['badges_position'] ) ? $meta['badges_position'] : 'left', 'badge_alignment' => ! empty( $meta['badges_alignment'] ) ? $meta['badges_alignment'] : 'top', 'badge_preset' => ! empty( $meta['custom_badge_preset'] ) ? $meta['custom_badge_preset'] : 'preset-1', // Link. 'image_link' => ! empty( $meta['image_link'] ), 'title_link' => ! empty( $meta['title_link'] ), 'hover_btn_text' => ! empty( $meta['hover_btn_text'] ) ? $meta['hover_btn_text'] : esc_html__( 'See Details', 'shopbuilder' ), 'show_hover_btn_icon' => ! empty( $meta['show_hover_btn_icon'] ), 'hover_btn_icon' => ! empty( $meta['hover_btn_icon'] ) ? $meta['hover_btn_icon'] : [], 'custom_link' => ! empty( $meta['custom_link'] ) ? $meta['custom_link'] : null, // Slider. 'd_group' => ! empty( $meta['cols_group'] ) ? $meta['cols_group'] : 1, 't_group' => ! empty( $meta['cols_group_mobile'] ) ? $meta['cols_group_mobile'] : 1, 'm_group' => ! empty( $meta['cols_group_mobile'] ) ? $meta['cols_group_mobile'] : 1, 'auto_play' => ! empty( $meta['slide_autoplay'] ), 'stop_on_hover' => ! empty( $meta['pause_hover'] ), 'slider_nav' => ! empty( $meta['slider_nav'] ), 'slider_dot' => ! empty( $meta['slider_pagi'] ), 'loop' => ! empty( $meta['slider_loop'] ), 'lazy_load' => ! empty( $meta['slider_lazy_load'] ), 'auto_height' => ! empty( $meta['slider_auto_height'] ), 'speed' => ! empty( $meta['slide_speed'] ) ? $meta['slide_speed'] : 2000, 'space_between' => isset( $meta['grid_gap']['size'] ) && strlen( $meta['grid_gap']['size'] ) ? $meta['grid_gap']['size'] : 30, 'auto_play_timeout' => ! empty( $meta['autoplay_timeout'] ) ? $meta['autoplay_timeout'] : 5000, 'nav_position' => ! empty( $meta['slider_nav_position'] ) ? $meta['slider_nav_position'] : 'top', 'left_arrow_icon' => ! empty( $meta['slider_left_arrow_icon'] ) ? $meta['slider_left_arrow_icon'] : [], 'right_arrow_icon' => ! empty( $meta['slider_right_arrow_icon'] ) ? $meta['slider_right_arrow_icon'] : [], ]; } /** * Setting up content visibility * * @param array $settings Elementor settings. * @return array */ public static function content_visibility( $settings ) { $visibility = []; if ( ! empty( $settings['show_title'] ) ) { $visibility[] = 'title'; } if ( ! empty( $settings['show_short_desc'] ) ) { $visibility[] = 'excerpt'; } if ( ! empty( $settings['show_price'] ) ) { $visibility[] = 'price'; } if ( ! empty( $settings['show_rating'] ) ) { $visibility[] = 'rating'; } if ( ! empty( $settings['show_badges'] ) ) { $visibility[] = 'badges'; } if ( ! empty( $settings['show_categories'] ) ) { $visibility[] = 'categories'; } if ( ! empty( $settings['show_swatches'] ) ) { $visibility[] = 'swatches'; } if ( ! empty( $settings['show_vs_clear_btn'] ) ) { $visibility[] = 'clear-btn'; } if ( ! empty( $settings['show_count'] ) ) { $visibility[] = 'count'; } if ( ! empty( $settings['show_wishlist'] ) ) { $visibility[] = 'wishlist'; } if ( ! empty( $settings['show_compare'] ) ) { $visibility[] = 'compare'; } if ( ! empty( $settings['show_quick_view'] ) ) { $visibility[] = 'quick_view'; } if ( ! empty( $settings['show_add_to_cart'] ) ) { $visibility[] = 'add_to_cart'; } return $visibility; } /** * Set Default Layout. * * @param string $layout Layout. * * @return string */ public static function set_default_layout( $layout ) { $is_list = preg_match( '/list/', $layout ); $is_cat_single = preg_match( '/category-single/', $layout ); $is_cat = preg_match( '/category/', $layout ); $is_carousel = preg_match( '/slider/', $layout ); $default = 'grid-layout1'; if ( $is_list ) { $default = 'list-layout1'; } elseif ( $is_cat_single ) { $default = 'category-single-layout1'; } elseif ( $is_cat ) { $default = 'category-layout1'; } elseif ( $is_carousel ) { $default = 'slider-layout1'; } return $default; } /** * Default layout columns. * * @param int $layout Layout. * * @return int */ public static function default_columns( $layout ) { $columns = 4; switch ( $layout ) { case 'grid-layout2': case 'slider-layout2': $columns = 3; break; case 'list-layout1': case 'list-layout2': $columns = 1; break; case 'category-layout1': $columns = 6; break; default: $columns = 4; break; } return $columns; } /** * Pagination JSON data. * * @param array $metas Data set. * @return string */ public static function pagination_data( $metas ) { $el_data = self::meta_dataset( $metas ); return ' data-pagination=\'' . esc_js( wp_json_encode( $el_data ) ) . '\''; } /** * Slider options. * * @param array $meta Meta values. * @return array */ public static function slider_data( array $meta ) { $has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot'; $has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav'; $d_col = 0 === $meta['d_cols'] ? self::default_columns( $meta['layout'] ) : $meta['d_cols']; $t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols']; $m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols']; $slider_options = [ 'slidesPerView' => absint( $d_col ), 'slidesPerGroup' => absint( $meta['d_group'] ), 'spaceBetween' => absint( $meta['space_between'] ), 'speed' => absint( $meta['speed'] ), 'loop' => $meta['loop'], 'autoHeight' => $meta['auto_height'], 'preloadImages' => ! $meta['lazy_load'], 'lazy' => $meta['lazy_load'], 'breakpoints' => [ 0 => [ 'slidesPerView' => absint( $m_col ), 'slidesPerGroup' => absint( $meta['m_group'] ), 'pagination' => [ 'dynamicBullets' => true, ], ], 767 => [ 'slidesPerView' => absint( $t_col ), 'slidesPerGroup' => absint( $meta['t_group'] ), 'pagination' => [ 'dynamicBullets' => false, ], ], 991 => [ 'slidesPerView' => absint( $d_col ), 'slidesPerGroup' => absint( $meta['d_group'] ), ], ], ]; if ( $meta['auto_play'] ) { $slider_options['autoplay'] = [ 'delay' => absint( $meta['auto_play_timeout'] ), 'pauseOnMouseEnter' => $meta['stop_on_hover'], 'disableOnInteraction' => false, ]; } $carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots; return [ 'data' => ' data-options=\'' . esc_js( wp_json_encode( $slider_options ) ) . '\'', 'class' => $carouselClass, ]; } /** * Renders pagination * * @param object $wp_query WP_Query object. * @param array $meta Meta values. * @param int $limit Post limit. * @param int $per_page Posts per page. * @return string */ public static function render_pagination( $wp_query, $meta, $limit, $per_page ) { $html_utility = null; $html = null; $is_grid = preg_match( '/grid-layout/', $meta['layout'] ) || preg_match( '/list-layout/', $meta['layout'] ); $posts_per_page = $wp_query->query_vars['posts_per_page']; $total_page = $wp_query->max_num_pages; if ( $limit && ( empty( $wp_query->query['tax_query'] ) ) ) { $found_post = $wp_query->found_posts; if ( $per_page && $found_post > $per_page ) { $found_post = $limit; $total_page = ceil( $found_post / $per_page ); } } $total_page = absint( $total_page ); if ( 'pagination' === $meta['posts_loading_type'] && $is_grid && empty( $meta['filters'] ) ) { $html_utility .= Fns::custom_pagination( $total_page, $posts_per_page ); } if ( $html_utility ) { $html .= '