get_settings; } /** * Container Wrapper HTML. * * @param string $content The content. * @param array $settings Settings. * @param string $class Class. * @param string $template Template name. * @param bool $fullwidth Fullwidth check. * * @return string */ public function container( $content, $settings, $class = '', $template = '', $fullwidth = false ) { $layout_id = 'rtsb-container-' . absint( wp_rand() ); $container_attr = null; $cart_txt_class = ''; $container_class = 'rtsb-elementor-container products rtsb-pos-r ' . esc_attr( $class ); $metas = RenderHelpers::meta_dataset( $settings, $template ); $layout = $metas['layout']; $animation = $metas['hover_animation']; $is_cat = preg_match( '/category/', $layout ); $is_carousel = preg_match( '/slider/', $layout ); if ( ! $is_cat ) { $cart_txt_class = $metas['show_cart_text'] ? ' has-cart-text' : ' no-cart-text'; } if ( $is_carousel ) { $fullwidth = true; } $badge_class = [ 'position' => $metas['badge_position'], 'alignment' => $metas['badge_alignment'], ]; if ( ! in_array( $layout, array_keys( Fns::free_layouts() ), true ) ) { $layout = RenderHelpers::set_default_layout( $layout ); } if ( $is_carousel ) { $pagination_attr = ! empty( $metas['show_filter'] ) ? RenderHelpers::pagination_data( $settings, $template ) : ''; } elseif ( $is_cat ) { $pagination_attr = ''; } else { $pagination_attr = RenderHelpers::pagination_data( $settings, $template ); } if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) { $container_class .= ' no-clear-btn'; } $style_attr = ' style="--rtsb-default-columns: ' . esc_attr( RenderHelpers::default_columns( $layout ) ) . '"'; $tooltip_attr = ' data-tooltip-position="' . esc_attr( $metas['tooltip_position'] ) . '"'; $view_mode = $settings['view_mode'] ?? 'grid'; if ( isset( $_GET['displayview'] ) ) { $view_mode = sanitize_text_field( wp_unslash( $_GET['displayview'] ) ); } if ( 'list' == $view_mode && ! empty( $metas['tooltip_position_list'] ) ) { $tooltip_attr = ' data-tooltip-position="' . esc_attr( $metas['tooltip_position_list'] ) . '"'; } $container_attr .= ' data-layout="' . esc_attr( $layout ) . '"' . $style_attr . $tooltip_attr . $pagination_attr; $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'] ); if ( $metas['show_overlay'] ) { $container_class .= ' has-overlay'; } if ( in_array( 'single-cat', $metas['visibility'], true ) ) { $container_class .= ' show-single-cat'; } $container_class = apply_filters( 'rtsb/product/container/class', $container_class, $settings ); $this->html = '
' . esc_html__( 'Please select a category.', 'shopbuilder' ) . '
'; } $taxonomy_query = get_term( $term, $taxonomy ); } else { // Query Args. $args = ( new QueryArgs() )->buildArgs( $metas, 'category' ); $taxonomy_query = get_terms( $args ); } if ( ! empty( $taxonomy_query ) ) { // Row. $this->row( $this->category_loop( $taxonomy_query, $metas, $template, $is_single ), $metas ); } else { $this->html .= '' . esc_html__( 'No categories found', 'shopbuilder' ) . '
'; } // Container. $this->container( $this->html, $settings, 'rtsb-categories-container', $is_single ); return $this->html; } /** * Render Category View. * * @param string $template Template name. * @param array $settings Control settings. * * @return string */ public function social_share_view( $template, $settings ) { $this->get_settings = $settings; $share_items = []; foreach ( $settings['share_platforms'] as $platform ) { $share_items[] = [ 'share_items' => $platform['share_items'], 'share_text' => $platform['share_text'], ]; } if ( ! empty( $share_items ) && is_array( $share_items ) ) { $arg['p_id'] = get_the_ID(); $arg['share_items'] = $share_items; $arg['preset'] = $settings['layout']; $arg['direction'] = ! empty( $settings['layout_direction'] ) ? $settings['layout_direction'] : 'horizontal'; $arg['show_icon'] = ! empty( $settings['show_share_icon'] ); $arg['show_text'] = ! empty( $settings['show_share_text'] ); $arg['show_pre_text'] = ! empty( $settings['show_share_pre_text'] ); $arg['share_pre_text'] = ! empty( $settings['share_pre_text'] ) ? $settings['share_pre_text'] : ''; $arg['raw_settings'] = $this->get_settings_for_display(); $this->html = Fns::load_template( $template, $arg, true ); } else { $this->html = '' . esc_html__( 'Please select a social sharing platform.', 'shopbuilder' ) . '
'; } return $this->html; } /** * Builds an array with meta values. * * @param array $meta Meta values. * @param int $post_id Post ID. * @param bool $lazy_load Lazy Load. * @param int $i Integer. * * @return array */ public function arg_dataset( array $meta, int $post_id, bool $lazy_load = false, $i = 0 ) { if ( ( empty( $meta ) && ! $post_id ) || ! in_array( get_post_type( $post_id ), [ 'product_variation', 'product' ] ) ) { return []; } global $post; $arg = []; $_product = wc_get_product( $post_id ); $p_type = $_product->get_type(); $arg['class'] = null; $arg['grid'] = null; $arg['anchor_class'] = null; $arg['hover_img_html'] = null; $arg['s_link'] = []; $arg['add_to_cart'] = ''; $arg['p_id'] = $post_id; $arg['p_link'] = get_permalink(); $arg['p_sale'] = ''; $arg['has_attributes'] = $_product->is_type( 'variable' ) && $_product->get_attributes(); $arg['raw_settings'] = ! empty( $meta['raw_settings'] ) ? $meta['raw_settings'] : []; $cart_icon_html = ''; $layout = $meta['layout']; $arg['target'] = '_self'; $arg['f_img'] = $meta['f_img']; $arg['items'] = $meta['visibility']; $arg['title_tag'] = $meta['title_tag']; $arg['title_class'] = 'product-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' ); $arg['title'] = Fns::text_truncation( get_the_title(), $meta['title_limit_custom'] ); $arg['excerpt_limit'] = $meta['excerpt_limit']; $arg['excerpt'] = wpautop( Fns::text_truncation( do_shortcode( $post->post_excerpt ), $meta['excerpt_limit_custom'] ) ); $arg['title_link'] = $meta['title_link']; $arg['image_link'] = $meta['image_link']; $arg['out_of_stock'] = $meta['out_of_stock_badge_text']; $arg['action_btn_preset'] = $meta['btn_preset']; $arg['action_btn_position'] = $meta['btn_position']; $arg['swatch_position'] = $meta['swatch_position']; $arg['swatch_type'] = $meta['swatch_type']; $arg['tooltip_position'] = $meta['tooltip_position']; $is_list = preg_match( '/list/', $layout ); $is_carousel = preg_match( '/slider/', $layout ); if ( ! $is_carousel ) { $arg['grid'] .= 'rtsb-col-grid '; $arg['class'] .= ' even-grid-item '; } else { $arg['grid'] .= 'rtsb-col-grid rtsb-col-full rtsb-slide-item swiper-slide '; } $d_cols = 0 === $meta['d_cols'] ? RenderHelpers::default_columns( $layout ) : $meta['d_cols']; $t_cols = 0 === $meta['t_cols'] ? 2 : $meta['t_cols']; $m_cols = 0 === $meta['m_cols'] ? 1 : $meta['m_cols']; $arg['grid'] .= 0 === $i % $d_cols ? ' row-last desktop-row-last' : ''; $arg['grid'] .= 0 === $i % $t_cols ? ' row-last tablet-row-last' : ''; $arg['grid'] .= 0 === $i % $m_cols ? ' row-last mobile-row-last' : ''; $arg['class'] .= 'rtsb-product'; if ( $is_list ) { $arg['class'] .= ' rtsb-product-list'; } $arg['class'] .= ' animated rtFadeIn'; if ( in_array( 'badges', $meta['visibility'], true ) ) { $arg['p_sale'] = Fns::get_sale_badge( $meta['sale_badge_type'], $meta['sale_badge_text'], $meta['out_of_stock_badge_text'] ); } $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] ); if ( ! $meta['show_cart_text'] ) { $meta['add_to_cart_text'] = ''; $meta['add_to_cart_success_text'] = ''; } if ( in_array( 'add_to_cart', $meta['visibility'], true ) ) { if ( ! empty( $meta['add_to_cart_icon'] ) ) { $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_icon'], 'cart-icon' ); } if ( ! empty( $meta['add_to_cart_success_icon'] ) ) { $cart_icon_html .= Fns::icons_manager( $meta['add_to_cart_success_icon'], 'cart-success-icon' ); } $cart_icon = '' . $cart_icon_html . ''; if ( $_product->is_purchasable() ) { if ( $_product->is_in_stock() ) { $arg['add_to_cart'] = $this->render_add_to_cart_button( get_permalink(), $post_id, $p_type, $meta['add_to_cart_text'], $meta['add_to_cart_success_text'], $cart_icon, $meta['add_to_cart_alignment'] ); } } } if ( in_array( 'quick_view', $meta['visibility'], true ) ) { add_filter( 'rtsb/module/quick_view/button_params', [ $this, 'button_classes' ] ); add_filter( 'rtsb/module/quick_view/icon_html', [ $this, 'quick_view_icon' ] ); } if ( in_array( 'compare', $meta['visibility'], true ) ) { add_filter( 'rtsb/module/compare/button_params', [ $this, 'button_classes' ] ); add_filter( 'rtsb/module/compare/icon_html', [ $this, 'compare_icon' ] ); } if ( in_array( 'wishlist', $meta['visibility'], true ) ) { add_filter( 'rtsb/module/wishlist/button_params', [ $this, 'button_classes' ] ); add_filter( 'rtsb/module/wishlist/icon_html', [ $this, 'wishlist_icon' ] ); } $arg['img_html'] = $meta['f_img'] ? Fns::get_product_image_html( 'product', $post_id, $meta['f_img_size'], $meta['default_img_id'], $meta['custom_img_size'], $lazy_load ) : null; if ( ! ( function_exists( 'rtwpvsp' ) && $_product->is_type( 'variable' ) && $_product->get_attributes() ) ) { $gallery_ids = $_product->get_gallery_image_ids(); if ( $meta['hover_img'] && ! empty( $gallery_ids ) ) { $arg['class'] .= ! $meta['gallery_img'] ? ' rtsb-double-img' : ''; if ( ! rtsb()->has_pro() ) { $arg['class'] .= ' rtsb-double-img'; } $arg['hover_img_html'] = Fns::get_product_image_html( 'product', $gallery_ids[0], $meta['f_img_size'], null, $meta['custom_img_size'], $lazy_load, true ); } } $arg['hover_btn_text'] = $meta['hover_btn_text']; if ( $meta['show_hover_btn_icon'] && ! empty( $meta['hover_btn_icon'] ) ) { $arg['hover_btn_icon'] = '' . Fns::icons_manager( $meta['hover_btn_icon'], 'hover-btn-icon' ) . ''; } $arg['img_args'] = [ 'p_id' => $arg['p_id'], 'title' => get_the_title(), 'p_link' => $arg['p_link'], 'image_link' => $arg['image_link'], 'img_html' => $arg['img_html'], 'hover_img_html' => $arg['hover_img_html'], 'meta' => $meta, ]; return apply_filters( 'rtsb/elementor/render/arg_dataset', $arg, $post_id, $meta, $lazy_load ); } /** * Builds an array with meta values. * * @param array $meta Meta values. * @param Object $query Category object. * @param bool $fullwidth Fullwidth check. * @param bool $lazy_load Lazy Load. * * @return array */ public function cat_arg_dataset( $meta, $query = null, $fullwidth = false, $lazy_load = false ) { if ( empty( $meta ) ) { return []; } $arg = []; $arg['class'] = null; $arg['grid'] = null; $arg['anchor_class'] = null; $arg['p_sale'] = null; $arg['count'] = max( $query->count, 0 ); $arg['count_position'] = $meta['count_position']; $arg['excerpt_position'] = $meta['cat_excerpt_position']; $arg['cat_link'] = get_term_link( $query ); $arg['target'] = '_self'; $arg['raw_settings'] = ! empty( $meta['raw_settings'] ) ? $meta['raw_settings'] : []; if ( ! empty( $meta['tag_term'] ) ) { $arg['tag_term'] = $meta['tag_term']; } if ( ! empty( $meta['custom_link']['url'] ) ) { $arg['cat_link'] = $meta['custom_link']['url']; $arg['target'] = $meta['custom_link']['is_external'] ? '_blank' : '_self'; } $title = $query->name; $excerpt = $query->description; if ( in_array( 'badges', $meta['visibility'], true ) ) { $arg['p_sale'] = $meta['custom_badge_text']; } $arg['badge_class'] = RenderHelpers::badge_class( $meta['badge_preset'] ); if ( $arg['count'] >= 0 ) { $prefix = ! empty( $meta['before_count'] ) ? $meta['before_count'] : ''; $suffix = ! empty( $meta['after_count'] ) ? $meta['after_count'] : ''; $arg['count'] = $prefix . $arg['count'] . $suffix; } if ( $meta['show_custom_title'] && ! empty( $meta['cat_custom_title'] ) ) { $title = $meta['cat_custom_title']; } if ( $meta['show_custom_excerpt'] && ! empty( $meta['cat_custom_excerpt'] ) ) { $excerpt = $meta['cat_custom_excerpt']; } $layout = $meta['layout']; $arg['c_img'] = $meta['c_img']; $arg['items'] = $meta['visibility']; $arg['title_tag'] = $meta['title_tag']; $arg['title_class'] = 'category-title rtsb-text-limit limit-' . $meta['title_limit'] . ( ! $meta['title_link'] ? ' no-link' : '' ); $arg['title'] = Fns::text_truncation( $title, $meta['title_limit_custom'] ); $arg['excerpt_limit'] = $meta['excerpt_limit']; $arg['excerpt'] = wpautop( Fns::text_truncation( $excerpt, $meta['excerpt_limit_custom'] ) ); $arg['title_link'] = $meta['title_link']; $arg['image_link'] = $meta['image_link']; if ( ! $fullwidth ) { $arg['grid'] .= 'rtsb-col-grid '; $arg['class'] .= ' even-grid-item '; } else { $arg['grid'] .= 'rtsb-col-grid '; } $arg['class'] .= 'rtsb-category-grid'; $arg['img_html'] = $meta['c_img'] ? Fns::get_product_image_html( 'category', $query->term_id, $meta['f_img_size'], $meta['default_img_id'], $meta['custom_img_size'], $lazy_load ) : null; if ( $meta['show_custom_image'] && ! empty( $meta['custom_image'] ) ) { $arg['img_html'] = Fns::get_product_image_html( 'custom', null, $meta['f_img_size'], $meta['custom_image'], $meta['custom_img_size'], $lazy_load ); } $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' : '' ); return $arg; } /** * Renders add to cart button. * * @param string $link Product link. * @param int $id Product ID. * @param string $type Product type. * @param string $text Custom text. * @param string $success Success text. * @param string $icon_html Custom icon. * @param string $alignment Icon alignment. * * @return string */ public function render_add_to_cart_button( $link, $id, $type, $text, $success, $icon_html, $alignment ) { $content = null; $tooltip_attr = ''; if ( empty( $text ) ) { $tooltip_attr = ' title="' . esc_attr__( 'Add to Cart', 'shopbuilder' ) . '"'; if ( 'variable' === $type ) { $tooltip_attr = ' title="' . esc_attr__( 'Select Options', 'shopbuilder' ) . '"'; } } ob_start(); do_action( 'rtsb/before/cart/button' ); $content .= ob_get_clean(); if ( 'variable' === $type ) { $content .= sprintf( '', esc_url( $link ), esc_html__( 'Select Options', 'shopbuilder' ), absint( $id ), esc_attr( $alignment ), empty( $text ) ? 'no-text' : 'has-text', $tooltip_attr, $icon_html, ); } else { $content .= sprintf( '%4$s%5$s', esc_url( $link ), absint( $id ), esc_attr( $type ), $icon_html, esc_html( $text ), esc_attr( $alignment ), empty( $text ) ? 'no-text' : 'has-text', $tooltip_attr, esc_html( $success ), ! empty( $success ) ? 'has-success-text' : 'no-success-text', ); } ob_start(); do_action( 'rtsb/after/cart/button' ); $content .= ob_get_clean(); return $content; } /** * Button classes. * * @param array $params Button params. * * @return array */ public function button_classes( $params ) { $params['classes'] = array_merge( $params['classes'], [ 'rtsb-action-btn', 'tipsy' ] ); return $params; } }