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. * @param bool $ajax_attr Ajax attributes. * * @return string */ public function container( $content, $settings, $class = '', $template = '', $fullwidth = false, $ajax_attr = true ) { $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']; $animation .= ' gallery-hover-' . ( ! empty( $settings['gallery_hover_animation'] ) ? $settings['gallery_hover_animation'] : 'fade' ); $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 ( ! rtsb()->has_pro() && ! in_array( $layout, array_keys( Fns::free_layouts() ), true ) ) { $layout = RenderHelpers::set_default_layout( $layout ); } $has_tab_filters = rtsb()->has_pro() && ! empty( $settings['tax_filter'] ); if ( $is_carousel ) { $pagination_attr = $has_tab_filters ? RenderHelpers::pagination_data( $settings, $template ) : ''; } elseif ( $is_cat ) { $pagination_attr = ''; } else { $ajax_pagination = ! empty( $settings['show_pagination'] ) && 'pagination' !== $settings['pagination_type']; $page = Fns::product_filters_has_ajax( 'shop' ) || Fns::product_filters_has_ajax( 'archive' ); $condition = rtsb()->has_pro() && $ajax_attr && ( $ajax_pagination || $has_tab_filters || $page ); $pagination_attr = $condition ? RenderHelpers::pagination_data( $settings, $template ) : ''; } if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) { $container_class .= ' no-clear-btn'; } $container_class .= ! empty( $metas['pagination'] ) ? ' rtsb-has-pagination' : ' rtsb-no-pagination'; $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'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['displayview'] ) ) { $view_mode = sanitize_text_field( wp_unslash( $_GET['displayview'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } 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'; } if ( ! empty( $settings['show_compare_text'] ) ) { $container_class .= ' has-compare-text'; } if ( ! empty( $settings['show_quick_view_text'] ) ) { $container_class .= ' has-quick-view-text'; } if ( ! empty( $settings['show_wishlist_text'] ) ) { $container_class .= ' has-wishlist-text'; } if ( empty( $settings['show_compare_icon'] ) ) { $container_class .= ' no-compare-icon'; } if ( empty( $settings['show_quick_view_icon'] ) ) { $container_class .= ' no-quick-view-icon'; } if ( empty( $settings['show_wishlist_icon'] ) ) { $container_class .= ' no-wishlist-icon'; } if ( empty( $settings['show_quick_checkout_icon'] ) ) { $container_class .= ' no-quick_checkout-icon'; } if ( $is_cat && empty( $settings['show_overlay'] ) ) { $container_class .= ' no-category-bg-overlay'; } $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 ( ! is_wp_error( $taxonomy_query ) && ! 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, $product; if ( ! $product instanceof WC_Product && $post_id ) { $product = wc_get_product( $post_id ); } $arg = []; $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['rating_args'] = []; $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() || 'grouped' === $p_type || 'external' === $p_type ) { 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, $category_loop = false ) { if ( empty( $meta ) ) { return []; } $arg = []; $products = null; $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' : '' ); if ( $category_loop ) { $query_args = [ 'product_category_id' => $query->term_id, 'limit' => -1, 'order' => 'DESC', 'orderby' => 'date', ]; $products_query = new \WC_Product_Query( $query_args ); $products = $products_query->get_products(); } return apply_filters( 'rtsb/elementor/render/cat_arg_dataset', $arg, $meta, $query, $fullwidth, $lazy_load, $products ); } /** * 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 = ''; $ext_link = get_post_meta( $id, '_product_url', true ); $btn_txt = get_post_meta( $id, '_button_text', true ); if ( empty( $text ) ) { $tooltip_attr = ' title="' . esc_attr__( 'Add to Cart', 'shopbuilder' ) . '"'; if ( 'variable' === $type ) { $tooltip_attr = ' title="' . esc_attr__( 'Select Options', 'shopbuilder' ) . '"'; } if ( 'grouped' === $type ) { $tooltip_attr = ' title="' . esc_attr__( 'View Products', 'shopbuilder' ) . '"'; } if ( 'external' === $type ) { $tooltip_txt = ! empty( $btn_txt ) ? esc_html( $btn_txt ) : esc_html__( 'Buy Product', 'shopbuilder' ); $tooltip_attr = ' title="' . esc_attr( $tooltip_txt ) . '"'; } } 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, ); } elseif ( 'grouped' === $type ) { $content .= sprintf( '', esc_url( $link ), esc_html__( 'View Products', 'shopbuilder' ), absint( $id ), esc_attr( $alignment ), empty( $text ) ? 'no-text' : 'has-text', $tooltip_attr, $icon_html, ); } elseif ( 'external' === $type ) { $content .= sprintf( '', ! empty( $ext_link ) ? esc_url( $ext_link ) : esc_url( $link ), ! empty( $btn_txt ) ? esc_html( $btn_txt ) : esc_html__( 'Buy Product', 'shopbuilder' ), absint( $id ), esc_attr( $alignment ), empty( $text ) ? 'no-text' : 'has-text', $tooltip_attr, $icon_html, ! empty( $ext_link ) ? ' target="_blank"' : '' ); } 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; } }