<?php
/**
 * Created by Sublime text 2.
 * User: thanhhiep992
 * Date: 05/09/15
 * Time: 10:00 AM
 */
if(class_exists("woocommerce")){
if(!function_exists('sv_vc_product_list'))
{
    function sv_vc_product_list($attr, $content = false)
    {
        $html = $view_html = '';
        extract(shortcode_atts(array(
            'style'         => 'block-offers',
            'image'         => '',
            'title'         => '',
            'pos_title'     => 'title-left',
            'title2'        => '',
            'number'        => '10',
            'cats'          => '',
            'order_by'      => 'date',
            'order'         => 'DESC',
            'product_type'  => '',
            'extra_info'    => 'yes',
            'item'          => '1',
            'item_res'      => '',
            'autoplay'      => 'false',
            'loop'          => 'true',
            'size'          => '',
            'time'          => '',
            'view_link'     => '',
            'image_ft'      => '',
            'image_link'    => '',
            'image_ft2'     => '',
            'image_link2'   => '',
            'cat_number'    => '8',
            'title_intop'   => '',
            'des_intop'     => '',
            'link_intop'    => '',
            'title_inmid'   => '',
            'des_inmid'     => '',
            'link_inmid'    => '',
            'title_inbot'   => '',
            'des_inbot'     => '',
            'link_inbot'    => '',
            'banner_pos'    => 'banner-left',
        ),$attr));
        $custom_list = array();
        $args = array(
            'post_type'         => 'product',
            'posts_per_page'    => $number,
            'orderby'           => $order_by,
            'order'             => $order,
            'paged'             => 1,
            );
        if($product_type == 'trendding'){
            $args['meta_query'][] = array(
                    'key'     => 'trending_product',
                    'value'   => 'on',
                    'compare' => '=',
                );
        }
        if($product_type == 'toprate'){
            $args['meta_key'] = '_wc_average_rating';
            $args['orderby'] = 'meta_value_num';
            $args['meta_query'] = WC()->query->get_meta_query();
            $args['tax_query'][] = WC()->query->get_tax_query();
        }
        if($product_type == 'mostview'){
            $args['meta_key'] = 'post_views';
            $args['orderby'] = 'meta_value_num';
        }
        if($product_type == 'bestsell'){
            $args['meta_key'] = 'total_sales';
            $args['orderby'] = 'meta_value_num';
        }
        if($product_type=='onsale'){
            $args['meta_query']['relation']= 'OR';
            $args['meta_query'][]=array(
                'key'   => '_sale_price',
                'value' => 0,
                'compare' => '>',                
                'type'          => 'numeric'
            );
            $args['meta_query'][]=array(
                'key'   => '_min_variation_sale_price',
                'value' => 0,
                'compare' => '>',                
                'type'          => 'numeric'
            );
        }
        if($product_type == 'featured'){
            $args['tax_query'][] =  array(
                                        'taxonomy' => 'product_visibility',
                                        'field'    => 'name',
                                        'terms'    => 'featured',
                                        'operator' => 'IN',
                                    );
        }
        if(!empty($cats)) {
            $custom_list = explode(",",$cats);
            $args['tax_query'][]=array(
                'taxonomy'=>'product_cat',
                'field'=>'slug',
                'terms'=> $custom_list
            );
        }
        $product_query = new WP_Query($args);
        $count = 1;
        $count_query = $product_query->post_count;
        $title_html =   '<div class="block-head">
                            <div class="block-title">';
        if(!empty($image)) $title_html .=   '<div class="block-icon">'.wp_get_attachment_image($image,'full').'</div>';
        $title_html .=          '<div class="block-text">
                                    <div class="block-title-text text-sm">'.esc_html($title).'</div>
                                    <div class="block-title-text text-lg">'.esc_html($title2).'</div>
                                </div>';
        if(!empty($time)){
            $title_html .=      '<div class="block-countdownt">
                                    <span class="countdown-lastest" data-date="'.$time.'"></span>
                                </div>';
        }
        $title_html .=      '</div>
                        </div>';
        $data_res = '';$data_margin = 0;
        if($item > 1) $data_margin = 20;
        if(!empty($item_res)){
            $item_data = explode(',', $item_res);
            if(is_array($item_data)){
                $count_data = 1;
                foreach ($item_data as $data_device) {
                    $data_device = explode(':', $data_device);
                    if(is_array($data_device)){
                        $data_res .= '"'.$data_device[0].'":{"items":'.$data_device[1].'}';
                        if($count_data < count($item_data)) $data_res .= ',';                        
                        $count_data++;
                    }
                }
            }
            $data_res = "'".'{'.$data_res.'}'."'";
        }
        else{
            $data_res = "'".'{"0":{"items":1},"600":{"items":1},"1000":{"items":'.$item.'}}'."'";
            if($item >= 2) $data_res = "'".'{"0":{"items":1},"480":{"items":2},"1000":{"items":'.$item.'}}'."'";
            if($item >= 4) $data_res = "'".'{"0":{"items":1},"480":{"items":2},"1000":{"items":3},"1170":{"items":'.$item.'}}'."'";
            if($item >= 5) $data_res = "'".'{"0":{"items":1},"480":{"items":2},"600":{"items":3},"1024":{"items":4},"1100":{"items":'.$item.'}}'."'";
        }
        if(!empty($size)) $size = explode('x', $size);
        else $size = array(330,330);
        switch ($style) {
            case 'list-home17':
                if($item > 1) $data_margin = 30;
                $html .=    '<div class="product-box17 recommendation">
                                <div class="product-tab">
                                    <div class="product-tab-header header-box17">
                                        <div class="block-text">
                                            <div class="block-title-text text-sm">'.esc_html($title).'</div>
                                            <div class="block-title-text text-lg">'.esc_html($title2).'</div>
                                        </div>
                                    </div>
                                    <div class="product-tab-content kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-page="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        if($count % 2 == 1) $html .=    '<div class="item">';
                        $html .=        '<div class="item-product-tab text-center">
                                            '.sv_product_thumb_hover2($size).'
                                            <div class="product-info">
                                                <div class="product-price">
                                                    '.$product->get_price_html().'
                                                </div>
                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                            </div>
                                        </div>';
                        if($count % 2 == 0 || $count == $count_query) $html .=    '</div>';
                        $count++;
                    }
                }
                $html .=            '</div>
                                </div>
                            </div>';
                break;

            case 'tab-home17':
                if(!empty($cats)){
                    $pre = rand(1,100);
                    if($item > 1) $data_margin = 30;
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <div class="product-tab-content kt-owl-carousel owl-style17" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<div class="item-product-tab text-center">
                                                            '.sv_product_thumb_hover2($size).'
                                                            <div class="product-info">
                                                                <div class="product-price">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                                                '.sv_get_rating_html2().'
                                                                '.sv_product_link('style2').'
                                                            </div>
                                                        </div>';
                                }
                            }
                            $tab_content .=         '</div>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="product-box17 option9 option17">
                                    <div class="product-tab">
                                        <div class="product-tab-header header-box17">';
                    if(!empty($title)){
                    $html .=                '<div class="block-text">
                                                <div class="block-title-text text-sm">'.esc_html($title).'</div>
                                                <div class="block-title-text text-lg">'.esc_html($title2).'</div>
                                            </div>';
                    }
                    $html .=                '<ul class="list-inline">   
                                                '.$tab_html.'
                                            </ul>
                                        </div>
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>
                                    </div>
                                </div>';
                }
                break;

            case 'list-home16':
                if($item > 1) $data_margin = 20;
                $banner_html = '';
                $banner_html .=     '<div class="col-md-5 col-sm-5 col-xs-12">
                                        <div class="banner-hover-image">
                                            <div class="banner-thumb">
                                                <a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a>
                                            </div>';
                if(!empty($title_intop) || !empty($des_intop) || !empty($link_intop)){
                $banner_html .=             '<div class="banner-info pos-top">
                                                <div class="inner-banner-info">
                                                    <p class="text-uppercase">'.esc_html($title_intop).'</p>
                                                    <h3 class="text-uppercase">'.esc_html($des_intop).'</h3>
                                                    <a href="'.esc_url($link_intop).'" class="shopnow">'.esc_html__("Shop now","megastore").'</a>
                                                </div>
                                            </div>';
                                            }
                if(!empty($title_inmid) || !empty($des_inmid) || !empty($link_inmid)){
                $banner_html .=             '<div class="banner-info pos-middle">
                                                <div class="inner-banner-info">
                                                    <p class="text-uppercase">'.esc_html($title_inmid).'</p>
                                                    <h3 class="text-uppercase">'.esc_html($des_inmid).'</h3>
                                                    <a href="'.esc_url($link_inmid).'" class="shopnow">'.esc_html__("Shop now","megastore").'</a>
                                                </div>
                                            </div>';
                                            }
                if(!empty($title_inbot) || !empty($des_inbot) || !empty($link_inbot)){
                $banner_html .=             '<div class="banner-info pos-bottom">
                                                <div class="inner-banner-info">
                                                    <p class="text-uppercase">'.esc_html($title_inbot).'</p>
                                                    <h3 class="text-uppercase">'.esc_html($des_inbot).'</h3>
                                                    <a href="'.esc_url($link_inbot).'" class="shopnow">'.esc_html__("Shop now","megastore").'</a>
                                                </div>
                                            </div>';
                                            }                
                $banner_html .=         '</div>
                                    </div>';

                $html .=    '<div class="product-box16">';
                $html .=    '<h2 class="title-box16"><a href="#">'.esc_html($title).'</a></h2>';
                $html .=        '<div class="content-product-box16 '.esc_attr($banner_pos).'">
                                    <div class="row">';
                if($banner_pos == 'banner-left') $html .= $banner_html;
                    $html .=            '<div class="col-md-7 col-sm-7 col-xs-12">
                                            <div class="product-slider16">
                                                <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                    if($product_query->have_posts()) {
                        while($product_query->have_posts()) {
                            $product_query->the_post();
                            global $product;
                            if($count % 2 == 1) $html .= '<li class="product">';
                            $html .=    '<div class="product-container">
                                            <div class="product-left">
                                                '.sv_product_thumb_hover($size).'                                                
                                            </div>
                                            <div class="product-right">
                                                <div class="product-name">
                                                    <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                </div>
                                                <div class="price-box">
                                                    '.$product->get_price_html().'
                                                </div>
                                                '.sv_get_rating_html().'
                                                '.sv_product_link().'
                                            </div>
                                        </div>';
                            if($count % 2 == 0 || $count == $count_query) $html .= '</li>';
                            $count++;
                        }
                    }
                    $html .=                    '</ul>
                                            </div>
                                        </div>';
                if($banner_pos == 'banner-right') $html .= $banner_html;
                $html .=            '</div>
                                </div>
                            </div>';
                break;

            case 'tab-home13':
                if(!empty($cats)){
                    if($item > 1) $data_margin = 20;
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            $term_childrents = get_term_children( $term->term_id, 'product_cat' );
                            $cat_count = 1;$cat_number = (int)$cat_number;                            
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <div class="product-tab-content kt-owl-carousel kt-owl-option6" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<div class="item-product-tab item-product13">
                                                            '.sv_product_thumb_hover3($size).'
                                                            <div class="product-info">
                                                                <div class="product-price">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                                                '.sv_product_link('style4').'
                                                            </div>
                                                        </div>';
                                }
                            }
                            $tab_content .=         '</div>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="product-box13">
                                    <div class="product-tab">
                                        <div class="title-tab13 text-center">';
                    if(!empty($title) || !empty($title2)){
                    $html .=                '<h2 class="text-uppercase">'.esc_html($title).'</h2>';
                    }
                    $html .=                '<ul class="list-inline">   
                                            '.$tab_html.'
                                            </ul>
                                        </div>
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>';
                    $html .=        '</div>';                    
                    $html .=    '</div>';
                }
                break;

            case 'tab-home10-2':
            case 'tab-home10':
                if(!empty($cats)){
                    if($item > 1) $data_margin = 20;
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            $term_childrents = get_term_children( $term->term_id, 'product_cat' );
                            $cat_count = 1;$cat_number = (int)$cat_number;                            
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <div class="product-tab-content kt-owl-carousel kt-owl-option5" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count = 1;
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $small_item =   '<div class="item-product10">
                                                        <div class="product-container">
                                                            <div class="product-left">
                                                                '.sv_product_thumb_hover($size).'
                                                            </div>
                                                            <div class="product-right">
                                                                <div class="product-name">
                                                                    <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                </div>
                                                                <div class="product-price price-box">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                '.sv_get_rating_html().'
                                                                '.sv_product_link().'
                                                            </div>
                                                        </div>
                                                    </div>';
                                    $thumb_id = array(get_post_thumbnail_id());
                                    $attachment_ids = $product->get_gallery_image_ids();
                                    $attachment_ids = array_merge($thumb_id,$attachment_ids);
                                    $gal_block = '';$i = 1;
                                    foreach ( $attachment_ids as $attachment_id ) {
                                        $image_link = wp_get_attachment_url( $attachment_id );
                                        if ( ! $image_link )
                                            continue;
                                        $image_title    = esc_attr( get_the_title( $attachment_id ) );
                                        $image_caption  = esc_attr( get_post_field( 'post_excerpt', $attachment_id ) );
                                        $image       = wp_get_attachment_image( $attachment_id, array(440,440), 0, $attr = array(
                                            'title' => $image_title,
                                            'alt'   => $image_title
                                            ) );
                                        if($i == 1) $active = 'active';
                                        else $active = '';
                                        $gal_block .=    '<a class="'.$active.'" href="'.wp_get_attachment_url($attachment_id).'">'.$image.'</a>';            
                                        $i++;
                                    }
                                    $large_item =   '<div class="product-main">
                                                        <div class="product-container">
                                                            <div class="product-left">
                                                                <div class="product-thumb">
                                                                    <a class="product-img" href="'.esc_url(get_the_permalink()).'">'.get_the_post_thumbnail(get_the_ID(),array(440,440)).'</a>
                                                                    <a title="'.esc_html__("Quick View","megastore").'" data-product-id="'.get_the_id().'" href="'.esc_url(get_the_permalink()).'" class="product-quick-view btn-quick-view">'.esc_html__("Quick View","megastore").'</a>
                                                                    <div class="pro-gal">
                                                                        '.$gal_block.'
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="product-right">
                                                                <div class="product-name">
                                                                    <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                </div>
                                                                <div class="product-price price-box">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                '.sv_product_link().'
                                                            </div>
                                                        </div>
                                                    </div>';
                                    if($style == 'tab-home10-2'){
                                        if($count % 7 == 1){
                                            $tab_content .=     '<div class="list-product10 product-main-right products clearfix">
                                                                    <div class="list-pro-right10">
                                                                        <div class="clearfix">';
                                            $tab_content .=                 $small_item;
                                            if($count == $count_query) $tab_content .=   '</div>
                                                                    </div>';  
                                        }
                                        else{
                                            if($count % 7 == 0 ){
                                                $tab_content .=     '<div class="list-pro-left10">
                                                                        '.$large_item.'
                                                                    </div>';
                                            }
                                            else{
                                                $tab_content .=     $small_item;
                                                if($count % 7 == 6 || $count == $count_query) $tab_content .=   '</div>
                                                                    </div>';
                                            }
                                        }
                                        if($count % 7 == 0 || $count == $count_query) $tab_content .=     '</div>';
                                    }
                                    else{
                                        if($count % 7 == 1){
                                            $tab_content .=     '<div class="list-product10 products clearfix">
                                                                    <div class="list-pro-left10">';
                                            $tab_content .=             $large_item;
                                            $tab_content .=         '</div>';
                                        }
                                        else{
                                            if($count % 7 == 2) $tab_content .= '<div class="list-pro-right10">
                                                                                    <div class="clearfix">';
                                            $tab_content .=     $small_item;
                                            if($count % 7 == 0 || $count == $count_query) $tab_content .=     '</div>
                                                                                </div>';
                                        }
                                        if($count % 7 == 0 || $count == $count_query) $tab_content .=     '</div>';
                                    }
                                    $count++;
                                }
                            }
                            $tab_content .=         '</div>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="product-box9 product-box10">
                                    <div class="product-tab">
                                        <div class="product-tab-header">';
                    if(!empty($title) || !empty($title2)){
                    $html .=                '<div class="block-text">
                                                <div class="block-title-text text-sm">'.esc_html($title).'</div>
                                                <div class="block-title-text text-lg">'.esc_html($title2).'</div>
                                            </div>';
                    }
                    $html .=                '<ul class="list-inline">   
                                            '.$tab_html.'
                                            </ul>
                                        </div>
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>';
                    $html .=        '</div>';                    
                    $html .=    '</div>';
                }
                break;

            case 'tab-home9':
                if(!empty($cats)){
                    if($item > 1) $data_margin = 20;
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            $term_childrents = get_term_children( $term->term_id, 'product_cat' );
                            $cat_count = 1;$cat_number = (int)$cat_number;                            
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <div class="product-tab-content kt-owl-carousel kt-owl-option5" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<div class="item-product-tab">
                                                            '.sv_product_thumb_hover2($size).'
                                                            <div class="product-info">
                                                                <div class="product-price price-box">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                                                '.sv_get_rating_html2().'
                                                                '.sv_product_link('style2').'
                                                            </div>
                                                        </div>';
                                }
                            }
                            $tab_content .=         '</div>
                                                </div>';
                        }
                    }
                    $bn_class = 'no-banner';
                    if(!empty($image_ft) || !empty($image_ft2)) $bn_class = '';
                    $html .=    '<div class="product-box9 option9 '.esc_attr($bn_class).'">
                                    <div class="product-tab">
                                        <div class="product-tab-header">';
                    if(!empty($title) || !empty($title2)){
                    $html .=                '<div class="block-text">
                                                <div class="block-title-text text-sm">'.esc_html($title).'</div>
                                                <div class="block-title-text text-lg">'.esc_html($title2).'</div>
                                            </div>';
                    }
                    $html .=                '<ul class="list-inline">   
                                            '.$tab_html.'
                                            </ul>
                                        </div>
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>';
                    $html .=        '</div>';
                    if(!empty($image_ft) || !empty($image_ft2)){
                        $html .=        '<div class="list-adv-bottom">
                                            <div class="row">';
                        if(!empty($image_ft)){
                            if(!empty($image_ft2)) $html .=        '<div class="col-md-6 col-sm-6 col-xs-12">';
                            else $html .=        '<div class="col-md-12 col-sm-12 col-xs-12">';
                                $html .=            '<div class="adv-bottom">
                                                        <a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a>
                                                    </div>
                                                </div>';
                        }
                        if(!empty($image_ft2)){
                                $html .=        '<div class="col-md-6 col-sm-6 col-xs-12">
                                                    <div class="adv-bottom">
                                                        <a href="'.esc_url($image_link2).'">'.wp_get_attachment_image($image_ft2,'full').'</a>
                                                    </div>
                                                </div>';
                        }
                        $html .=            '</div>
                                        </div>';
                    }
                    $html .=    '</div>';
                }
                break;

            case 'list-home8':
                $data_margin = 20;
                $html .=    '<div class="block block-cat option8">
                                <div class="block-head">';
                if(!empty($title)) $html .=    '<h4 class="widget-title">'.esc_html($title).'</h4>';
                $html .=    '</div>
                                <div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=    '<li>
                                        <div class="item-product">
                                            <div class="product-info">
                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                                <div class="product-price price-box">
                                                    '.$product->get_price_html().'
                                                </div>
                                                '.sv_get_rating_html2().'
                                            </div>
                                            <div class="product-thumb">
                                                <a class="product-thumb-link" href="'.esc_url(get_the_permalink()).'">'.get_the_post_thumbnail(get_the_ID(),$size).'</a>
                                                '.sv_product_link('style3').'
                                            </div>
                                        </div>
                                    </li>';
                    }
                }
                $html .=            '</ul>
                                </div>
                            </div>';
                break;

            case 'list-home6':
                if($item > 1) $data_margin = 30;
                $html .=    '<div class="new-product6">
                                <h2>'.esc_html($title).'</h2>
                                <div class="product-tab-content kt-owl-carousel kt-owl-option6" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=    '<div class="item-product6">
                                        '.sv_product_thumb_hover2($size).'
                                        <div class="product-info">
                                            <div class="product-price price-box">
                                                '.$product->get_price_html().'
                                            </div>
                                            <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                            <p class="product-desc">'.sv_substr(get_the_excerpt(),0,70).'</p>
                                            '.sv_product_link('style2').'
                                        </div>
                                    </div>';
                    }
                }
                $html .=        '</div>
                            </div>';
                break;

            case 'sale-home6':
                $html .=    '<div class="big-sale clearfix">
                                <div class="big-sale-banner">
                                    <div class="banner-thumb"><a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a></div>
                                    <div class="banner-info">
                                        <h3>'.esc_html($title2).'</h3>
                                        <h2>'.esc_html($title).'</h2>
                                    </div>
                                </div>
                                <div class="product-big-sale kt-owl-carousel kt-owl-option6" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=    '<div class="item-product-sale6 item-product6">
                                        '.sv_product_thumb_hover2($size).'
                                        <div class="product-info">
                                            <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                            <div class="product-price price-box">
                                                '.$product->get_price_html().'
                                            </div>
                                            '.sv_product_link('style2').'
                                        </div>
                                    </div>';
                    }
                }
                $html .=        '</div>
                            </div>';
                break;

            case 'tab-home5':
                if(!empty($cats)){
                    if($item > 1) $data_margin = 22;
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            $term_childrents = get_term_children( $term->term_id, 'product_cat' );
                            $cat_count = 1;$cat_number = (int)$cat_number;                            
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <div class="product-tab-content kt-owl-carousel kt-owl-option5" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<div class="item-product-tab">
                                                            '.sv_product_thumb_hover2($size).'
                                                            <div class="product-info">
                                                                <div class="product-price price-box">
                                                                    '.$product->get_price_html().'
                                                                </div>
                                                                <h3 class="product-title"><a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a></h3>
                                                                '.sv_get_rating_html2().'
                                                                '.sv_product_link('style2').'
                                                            </div>
                                                        </div>';
                                }
                            }
                            $tab_content .=         '</div>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="option5 product-tab '.esc_attr($pos_title).'">
                                    <div class="block-head clearfix">';
                    if(!empty($title)){
                    $html .=            '<div class="product-tab-title"><h2>'.esc_html($title).'</h2></div>';
                    }
                    $html .=            '<div class="product-tab-header">
                                            <ul class="list-inline">   
                                                '.$tab_html.'
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="tab-container">
                                        '.$tab_content.'
                                    </div>';
                    if(!empty($view_link)) $html .='<div class="link-view-all"><a href="'.esc_url($view_link).'">'.esc_html__("View all products","megastore").' <i class="fa fa-angle-right" aria-hidden="true"></i></a></div>';
                    $html .=    '</div>';
                }
                break;
            case 'list-home7-small':
                $bn_class = 'no-banner';
                if(!empty($image_ft)) $bn_class = '';
                $data_margin = 0;
                $html .=    '<div class="block block-top-seller7 '.esc_attr($bn_class).'">
                                '.$title_html.'
                                <div class="block-inner clearfix">
                                    <div class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        if($count % 5 == 1) $html .=    '<div class="clearfix">';
                        $html .=            '<div class="product">
                                                '.sv_product_thumb_hover($size,'image').'
                                                <div class="product-name">
                                                    <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                </div>
                                                <div class="price-box">
                                                    '.$product->get_price_html().'
                                                </div>
                                                '.sv_get_rating_html2().'
                                            </div>';
                        if($count % 5 == 0 || $count == $count_query) $html .=    '</div>';
                        $count++;
                    }
                }
                $html .=            '</div>';
                if(!empty($image_ft)){
                $html .=            '<div class="upto-banner">
                                        <a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a>
                                    </div>';
                                }
                $html .=        '</div>
                            </div>';
                break;

            case 'list-home7':
                $data_margin = 0;
                $html .=    '<div class="block block-product7">
                                '.$title_html.'
                                <div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        if($count % 2 == 1) $html .=    '<li class="product">';
                        $html .=            '<div class="product-container">
                                                <div class="product-left">';
                        $html .=                    sv_product_thumb_hover($size);
                        if($extra_info == 'yes'){
                            $html .=                '<div class="product-status">
                                                        '.sv_get_new_html().'
                                                        '.sv_get_saleoff_html().'
                                                    </div>';
                        }
                        $html .=                '</div>
                                                <div class="product-right">
                                                    <div class="product-name">
                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                    </div>
                                                    <div class="price-box">
                                                        '.$product->get_price_html().'
                                                    </div>
                                                    '.sv_get_rating_html2().'
                                                    '.sv_product_link().'
                                                </div>
                                            </div>';
                        if($count % 2 == 0 || $count == $count_query) $html .=    '</li>';
                        $count++;
                    }
                }
                $html .=            '</ul>
                                </div>
                            </div>';
                break;

            case 'list-widget':
                $html .=    '<div class="block block-specials">
                                <div class="block-head">'.esc_html($title).'</div>
                                <div class="block-inner">';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=    '<div class="product">
                                        <div class="image">
                                            <a href="'.esc_url(get_the_permalink()).'">'.get_the_post_thumbnail(get_the_ID(),$size).'</a>
                                        </div>
                                        <div class="product-name">
                                            <a href="'.esc_url(get_the_permalink()).'">'.get_the_title().'</a>
                                        </div>
                                        <div class="price-box">
                                            '.$product->get_price_html().'
                                        </div>
                                    </div>';
                    }
                }
                $html .=        '<a href="'.esc_url($view_link).'" class="button-radius">'.esc_html__("View All","megastore").'<span class="icon"></span></a>';
                $html .=        '</div>
                            </div>';
                break;

            case 'accordion-slider':
                $data_margin = 0;
                $html .=    '<div class="option3 clearfix"><div class="block block-top-review">';
                $html .=        '<div class="block-head clearfix">
                                    <h4 class="widget-title">'.esc_html($title).'</h4>
                                </div>';
                $html .=        '<div class="block-inner">
                                    <div class="kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        if($count % 5 == 1){
                            $f_class = 'active';
                            $html .=    '<ul class="list-product">';
                        }
                        else $f_class = '';
                        $html .=        '<li class="product '.$f_class.'">
                                            <a class="product-name" href="'.esc_url(get_the_permalink()).'"><span class="order">'.$count.'</span>'.get_the_title().'</a>
                                            <div class="product-info">
                                                <div class="price-box">
                                                    '.$product->get_price_html().'
                                                </div>
                                                '.sv_get_rating_html().'
                                                <div class="product-img">
                                                    <a href="'.esc_url(get_the_permalink()).'">'.get_the_post_thumbnail(get_the_ID(),$size).'</a>
                                                </div>
                                            </div>
                                        </li>';
                        if($count % 5 == 0 || $count == $count_query){
                            $html .=    '</ul>';
                        }
                        $count++;
                    }
                }
                $html .=            '</div>
                                </div>
                            </div></div>';
                break;

            case 'cat-parent-tab-home3':
                if(!empty($cats)){
                    if($item > 1) $data_margin = 22;
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $childrent_html = '';
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            $term_childrents = get_term_children( $term->term_id, 'product_cat' );
                            $cat_count = 1;$cat_number = (int)$cat_number;
                            if(!empty($term_childrents)){
                                $childrent_html .= '<div class="sub-cat">
                                                        <ul>';
                                foreach ($term_childrents as $term_child) {
                                    $term_childrent = get_term_by( 'id',$term_child, 'product_cat' );
                                    $term_childrent_link = get_term_link( $term_childrent, 'product_cat' );
                                    if(is_object($term_childrent)){
                                    $childrent_html .=        '<li><a href="'.esc_url($term_childrent_link).'">'.$term_childrent->name.'</a></li>';
                                    }
                                    if($cat_count >= $cat_number) break;
                                    $cat_count ++;
                                }
                                $childrent_html .=      '</ul>
                                                    </div>';
                            }
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    '.$childrent_html.'
                                                    <div class="cat-product">
                                                        <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<li class="product">
                                                            <div class="product-container">
                                                                <div class="product-left">';
                                    $tab_content .=                 sv_product_thumb_hover($size);
                                    if($extra_info == 'yes'){
                                        $tab_content .=             '<div class="product-status">
                                                                        '.sv_get_new_html().'
                                                                        '.sv_get_saleoff_html().'
                                                                    </div>';
                                    }
                                    $tab_content .=             '</div>
                                                                <div class="product-right">
                                                                    <div class="product-name">
                                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                    </div>
                                                                    <div class="price-box">
                                                                        '.$product->get_price_html().'
                                                                    </div>
                                                                    '.sv_product_link().'
                                                                </div>
                                                            </div>
                                                        </li>';
                                }
                            }
                            $tab_content .=         '</ul>
                                                </div></div>';
                        }
                    }
                    $html .=    '<div class="option3 clearfix"><div class="block3 tab-cat-products">
                                    <div class="block-head clearfix">';
                    if(!empty($title)){
                    $html .=            '<h3 class="block-title">'.esc_html($title).'</h3>';
                    }
                    $html .=            '<ul class="nav-tab tab-category">   
                                            '.$tab_html.'
                                        </ul>
                                    </div>
                                    <div class="block-inner">
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>
                                    </div>
                                </div></div>';
                }
                break;

            case 'hot-deals-home3':
                $html .=    '<div class="option3 clearfix"><div class="block3 block-hotdeals">';
                $html .=        '<div class="block-head clearfix">
                                    <h3 class="block-title">'.esc_html($title).'</h3>
                                    <a class="link-all" href="'.esc_url($view_link).'">'.esc_html__("View All","megastore").'</a>
                                </div>';
                $html .=        '<div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $sale_price_dates_to    = ( $date = get_post_meta( get_the_ID(), '_sale_price_dates_to', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
                        if(!empty($sale_price_dates_to)) $time = $sale_price_dates_to;
                        $html .=        '<li class="product">
                                            <div class="product-container">
                                                <div class="product-left">';
                        $html .=                    sv_product_thumb_hover($size);
                        if($extra_info == 'yes'){
                            $html .=                '<div class="product-status">
                                                        '.sv_get_new_html().'
                                                        '.sv_get_saleoff_html().'
                                                    </div>';
                        }
                        $html .=                '</div>
                                                <div class="product-right">
                                                    <div class="product-name">
                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                    </div>
                                                    <div class="price-box">
                                                        '.$product->get_price_html().'
                                                    </div>
                                                    '.sv_product_link().'
                                                </div>';
                        if(!empty($time)){
                        $html .=                '<div class="product-count-down">
                                                    <span class="countdown-lastest" data-date="'.$time.'"></span>
                                                </div>';
                                            }
                        $html .=            '</div>
                                        </li>';
                    }
                }
                $html .=            '</ul>
                                </div>
                            </div></div>';
                break;

            case 'cat-tab-home3':
                if(!empty($cats)){
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<li class="product">
                                                            <div class="product-container">
                                                                <div class="product-left">';
                                    $tab_content .=                 sv_product_thumb_hover($size);
                                    if($extra_info == 'yes'){
                                        $tab_content .=             '<div class="product-status">
                                                                        '.sv_get_new_html().'
                                                                        '.sv_get_saleoff_html().'
                                                                    </div>';
                                    }
                                    $tab_content .=             '</div>
                                                                <div class="product-right">
                                                                    <div class="product-name">
                                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                    </div>
                                                                    <div class="price-box">
                                                                        '.$product->get_price_html().'
                                                                    </div>
                                                                    '.sv_product_link().'
                                                                </div>
                                                            </div>
                                                        </li>';
                                }
                            }
                            $tab_content .=         '</ul>
                                                </div>';
                        }
                    }
                    $footer_html = '';
                    if(!empty($image_ft)){
                        $footer_html .= '<div class="block-footer">
                                            <div class="text-center banner-hover">
                                                <a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a>
                                            </div>
                                        </div>';
                    }
                    $html .=    '<div class="option3 clearfix"><div class="block3 block-new-arrivals">
                                    <div class="block-head clearfix">';
                    if(!empty($title)){
                    $html .=            '<h3 class="block-title">'.esc_html($title).'</h3>';
                    }
                    $html .=            '<ul class="nav-tab default">   
                                            '.$tab_html.'
                                        </ul>
                                    </div>
                                    <div class="block-inner">
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>
                                    </div>
                                    '.$footer_html.'
                                </div></div>';
                }
                break;

            case 'small-slider-home3':
                // $data_margin = 20;
                $html .=    '<div class="option3 clearfix"><div class="block block-specail3">';
                $html .=        '<div class="block-head clearfix">
                                    <h4 class="widget-title">'.esc_html($title).'</h4>
                                </div>';
                $html .=        '<div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=        '<li class="product">
                                            <div class="product-container">
                                                <div class="product-left">';
                        $html .=                    sv_product_thumb_hover($size);
                        if($extra_info == 'yes'){
                            $html .=                '<div class="product-status">
                                                        '.sv_get_new_html().'
                                                        '.sv_get_saleoff_html().'
                                                    </div>';
                        }
                        $html .=                '</div>
                                                <div class="product-right">
                                                    <div class="product-name">
                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                    </div>
                                                    <div class="price-box">
                                                        '.$product->get_price_html().'
                                                    </div>
                                                    '.sv_get_rating_html().'
                                                    '.sv_product_link().'
                                                </div>
                                            </div>
                                        </li>';
                    }
                }
                $html .=            '</ul>
                                </div>
                            </div></div>';
                break;

            case 'cat-tab-time':
                if(!empty($cats)){
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<li class="product">
                                                            <div class="product-container">
                                                                <div class="product-left">';
                                    $tab_content .=                 sv_product_thumb_hover($size);
                                    if($extra_info == 'yes'){
                                        $tab_content .=             '<div class="product-status">
                                                                        '.sv_get_new_html().'
                                                                        '.sv_get_saleoff_html().'
                                                                    </div>';
                                    }
                                    $tab_content .=             '</div>
                                                                <div class="product-right">
                                                                    <div class="product-name">
                                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                    </div>
                                                                    <div class="price-box">
                                                                        '.$product->get_price_html().'
                                                                    </div>
                                                                    '.sv_get_rating_html().'
                                                                    '.sv_product_link().'
                                                                </div>
                                                            </div>
                                                        </li>';
                                }
                            }
                            $tab_content .=         '</ul>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="block-hot-deals2">';                    
                    $html .=        '<div class="row">
                                        <div class="hot-deal-tab-wrap">
                                            <div class="hot-deal-tab">';
                    if(!empty($title)){
                        $html .=                '<h3 class="title">'.esc_html($title).'</h3>';
                    }
                    $html .=                    '<div class="countdown">
                                                    <span class="countdown-lastest" data-date="'.$time.'"></span>
                                                </div>
                                                <ul class="nav-tab">   
                                                    '.$tab_html.'
                                                </ul>
                                            </div>
                                        </div>
                                        <div class="tab-container-wrap">
                                            <div class="tab-container clearfix">
                                                '.$tab_content.'
                                            </div>
                                        </div>
                                    </div>
                                </div>';
                }
                break;

            case 'cat-tab':
                if(!empty($cats)){
                    $pre = rand(1,100);
                    $tabs = explode(",",$cats);
                    $tab_html = $tab_content = '';
                    foreach ($tabs as $key => $tab) {
                        $term = get_term_by( 'slug',$tab, 'product_cat' );
                        if(!empty($term) && is_object($term)){
                            if($key == 0) $active = 'active';
                            else $active = '';
                            $tab_html .=    '<li class="'.$active.'"><a href="'.esc_url('#'.$pre.$term->slug).'" data-toggle="tab" aria-expanded="true">'.$term->name.'</a></li>';
                            $tab_content .=    '<div role="tabpanel" class="tab-panel tab-pane fade in '.$active.'" id="'.$pre.$term->slug.'">
                                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                            unset($args['tax_query']);
                            $args['tax_query'][]=array(
                                'taxonomy'=>'product_cat',
                                'field'=>'slug',
                                'terms'=> $tab
                            );
                            $product_query = new WP_Query($args);
                            $count_query = $product_query->post_count;
                            if($product_query->have_posts()) {
                                while($product_query->have_posts()) {
                                    $product_query->the_post();
                                    global $product;
                                    $tab_content .=     '<li class="product">
                                                            <div class="product-container">
                                                                <div class="product-left">';
                                    $tab_content .=                 sv_product_thumb_hover($size);
                                    if($extra_info == 'yes'){
                                        $tab_content .=             '<div class="product-status">
                                                                        '.sv_get_new_html().'
                                                                        '.sv_get_saleoff_html().'
                                                                    </div>';
                                    }
                                    $tab_content .=             '</div>
                                                                <div class="product-right">
                                                                    <div class="product-name">
                                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                                    </div>
                                                                    <div class="price-box">
                                                                        '.$product->get_price_html().'
                                                                    </div>
                                                                    '.sv_get_rating_html().'
                                                                    '.sv_product_link().'
                                                                </div>
                                                            </div>
                                                        </li>';
                                }
                            }
                            $tab_content .=         '</ul>
                                                </div>';
                        }
                    }
                    $html .=    '<div class="block block-tabs">
                                    <div class="block-head">';
                    if(!empty($title)){
                    $html .=            '<div class="block-title">
                                            <div class="block-title-text text-lg">'.esc_html($title).'</div>
                                        </div>';
                    }
                    $html .=            '<ul class="nav-tab">   
                                            '.$tab_html.'
                                        </ul>
                                    </div>
                                    <div class="block-inner">
                                        <div class="tab-container">
                                            '.$tab_content.'
                                        </div>
                                    </div>
                                </div>';
                }
                break;

            case 'list-home11':
                $data_margin = 0;
                $html .=    '<div class="block-product-banner"><div class="block block-offers">';
                $html .=        $title_html;
                $html .=        '<div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=        '<li class="product">
                                            <div class="product-container">
                                                <div class="product-left">';
                        $html .=                    sv_product_thumb_hover($size);
                        if($extra_info == 'yes'){
                            $html .=                '<div class="product-status">
                                                        '.sv_get_new_html().'
                                                        '.sv_get_saleoff_html().'
                                                    </div>';
                        }
                        $html .=                '</div>
                                                <div class="product-right">
                                                    <div class="product-name">
                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                    </div>
                                                    <div class="price-box">
                                                        '.$product->get_price_html().'
                                                    </div>
                                                    '.sv_get_rating_html().'
                                                    '.sv_product_link().'
                                                </div>
                                            </div>
                                        </li>';
                    }
                }
                $html .=            '</ul>
                                </div>';
                if(!empty($image_ft)){
                    $html .=    '<div class="adv-bottom adv-bottom-home11">
                                    <a href="'.esc_url($image_link).'">'.wp_get_attachment_image($image_ft,'full').'</a>
                                </div>';
                }
                $html .=    '</div></div>';
                break;

            default:
                if($style == 'block-offers') $data_margin = 0;
                $html .=    '<div class="block '.$style.'">';
                $html .=        $title_html;
                $html .=        '<div class="block-inner">
                                    <ul class="products kt-owl-carousel" data-items="'.$item.'" data-autoplay="'.$autoplay.'" data-margin="'.$data_margin.'" data-loop="'.$loop.'"  data-nav="true" data-responsive='.$data_res.'>';
                if($product_query->have_posts()) {
                    while($product_query->have_posts()) {
                        $product_query->the_post();
                        global $product;
                        $html .=        '<li class="product">
                                            <div class="product-container">
                                                <div class="product-left">';
                        $html .=                    sv_product_thumb_hover($size);
                        if($extra_info == 'yes'){
                            $html .=                '<div class="product-status">
                                                        '.sv_get_new_html().'
                                                        '.sv_get_saleoff_html().'
                                                    </div>';
                        }
                        $html .=                '</div>
                                                <div class="product-right">
                                                    <div class="product-name">
                                                        <a href="'.esc_url(get_the_permalink()).'" title="'.get_the_title().'">'.get_the_title().'</a>
                                                    </div>
                                                    <div class="price-box">
                                                        '.$product->get_price_html().'
                                                    </div>
                                                    '.sv_get_rating_html().'
                                                    '.sv_product_link().'
                                                </div>
                                            </div>
                                        </li>';
                    }
                }
                $html .=            '</ul>
                                </div>
                            </div>';
                break;
        }
        wp_reset_postdata();
        return $html;
    }
}

if(function_exists('stp_reg_shortcode')) stp_reg_shortcode('sv_product_list','sv_vc_product_list');
add_action( 'vc_before_init_base','sv_add_list_product',10,100 );
if ( ! function_exists( 'sv_add_list_product' ) ) {
    function sv_add_list_product(){
        vc_map( array(
            "name"      => esc_html__("SV Product list", 'megastore'),
            "base"      => "sv_product_list",
            "icon"      => "icon-st",
            "category"  => '7Up-theme',
            "params"    => array(
                array(
                    'heading'     => esc_html__( 'Style', 'megastore' ),
                    'holder'      => 'div',
                    'type'        => 'dropdown',
                    'description' => esc_html__( 'Choose style to display.', 'megastore' ),
                    'param_name'  => 'style',
                    'value'       => array(
                        esc_html__('Default','megastore') => 'block-offers',
                        esc_html__('Default Small padding','megastore') => 'block-top-sellers',
                        esc_html__('List with countdown','megastore') => 'block-hot-deals',
                        esc_html__('Categories tab','megastore') => 'cat-tab',
                        esc_html__('Categories tab home 3','megastore') => 'cat-tab-home3',
                        esc_html__('Categories tab with countdown','megastore') => 'cat-tab-time',
                        esc_html__('Small slider home 3','megastore') => 'small-slider-home3',
                        esc_html__('Hot Deals home 3','megastore') => 'hot-deals-home3',
                        esc_html__('Categories parent tab home 3','megastore') => 'cat-parent-tab-home3',
                        esc_html__('Accordion slider','megastore') => 'accordion-slider',
                        esc_html__('List widget','megastore') => 'list-widget',
                        esc_html__('List home 7','megastore') => 'list-home7',
                        esc_html__('List home 7 small','megastore') => 'list-home7-small',
                        esc_html__('Tab Categories home 5','megastore') => 'tab-home5',
                        esc_html__('Sale home 6','megastore') => 'sale-home6',
                        esc_html__('List home 6','megastore') => 'list-home6',
                        esc_html__('List home 8','megastore') => 'list-home8',
                        esc_html__('Tab home 9','megastore') => 'tab-home9',
                        esc_html__('Tab home 10','megastore') => 'tab-home10',
                        esc_html__('Tab home 10(right)','megastore') => 'tab-home10-2',
                        esc_html__('List home 11(adv)','megastore') => 'list-home11',
                        esc_html__('tab home 13','megastore') => 'tab-home13',
                        esc_html__('List home 16','megastore') => 'list-home16',
                        esc_html__('Tab home 17','megastore') => 'tab-home17',
                        esc_html__('List home 17','megastore') => 'list-home17',
                        )
                ),
                array(
                    "type" => "textfield",
                    "heading" => esc_html__("Categories Childrent Number",'megastore'),
                    "param_name" => "cat_number",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("cat-parent-tab-home3"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "holder"        => "p",
                    "heading"       => esc_html__("Time Countdown",'megastore'),
                    'description'   => esc_html__( 'Entert time for countdown. Format is mm/dd/yyyy. Example: 12/15/2016', 'megastore' ),
                    "param_name"    => "time",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("block-hot-deals","cat-tab-time","hot-deals-home3"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("View Link",'megastore'),
                    "param_name"    => "view_link",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("hot-deals-home3","list-widget","tab-home5","list-home16"),
                        )
                ),
                array(
                    "type"          => "attach_image",
                    "heading"       => esc_html__("Image Title",'megastore'),
                    "param_name"    => "image",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array('list-home11',"block-hot-deals","block-offers","block-top-sellers","list-home7","list-home7-small"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "holder"        => "h4",
                    "heading"       => esc_html__("Title",'megastore'),
                    "param_name"    => "title",
                ),
                array(
                    "type"          => "dropdown",
                    "heading"       => esc_html__("Position Title",'megastore'),
                    "param_name"    => "pos_title",
                    "value"         => array(
                        esc_html__("Left",'megastore')   => 'title-left',
                        esc_html__("Right",'megastore')   => 'title-right',
                        esc_html__("No title",'megastore')   => 'title-none',
                        ),
                    "dependency"    => array(
                        "element"   => 'style',
                        "value"     => 'tab-home5',
                        )
                ),
                array(
                    "type"          => "textfield",
                    "holder"        => "h3",
                    "heading"       => esc_html__("Title 2",'megastore'),
                    "param_name"    => "title2",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array('list-home17','tab-home17','list-home11','tab-home10-2','tab-home10',"block-hot-deals","block-offers","block-top-sellers","list-home7","list-home7-small","sale-home6","tab-home9"),
                        )
                ),
                array(
                    'heading'     => esc_html__( 'Number', 'megastore' ),
                    'type'        => 'textfield',
                    'description' => esc_html__( 'Enter number of product. Default is 10.', 'megastore' ),
                    'param_name'  => 'number',
                ),
                array(
                    'heading'     => esc_html__( 'Product Type', 'megastore' ),
                    'type'        => 'dropdown',
                    'param_name'  => 'product_type',
                    'value' => array(
                        esc_html__('Default','megastore')            => '',
                        esc_html__('Trendding','megastore')          => 'trendding',
                        esc_html__('Featured Products','megastore')  => 'featured',
                        esc_html__('Best Sellers','megastore')       => 'bestsell',
                        esc_html__('On Sale','megastore')            => 'onsale',
                        esc_html__('Top rate','megastore')           => 'toprate',
                        esc_html__('Most view','megastore')          => 'mostview',
                    ),
                    'description' => esc_html__( 'Select Product View Type', 'megastore' ),
                ),
                array(
                    'holder'     => 'div',
                    'heading'     => esc_html__( 'Product Categories', 'megastore' ),
                    'type'        => 'checkbox',
                    'param_name'  => 'cats',
                    'value'       => sv_list_taxonomy('product_cat',false)
                ),
                array(
                    'type' => 'dropdown',
                    'heading' => esc_html__( 'Order By', 'megastore' ),
                    'value' => sv_get_order_list(),
                    'param_name' => 'orderby',
                    'description' => esc_html__( 'Select Orderby Type ', 'megastore' ),
                    'edit_field_class'=>'vc_col-sm-6 vc_column',
                ),
                array(
                    'heading'     => esc_html__( 'Order', 'megastore' ),
                    'type'        => 'dropdown',
                    'param_name'  => 'order',
                    'value' => array(                   
                        esc_html__('Desc','megastore')  => 'DESC',
                        esc_html__('Asc','megastore')  => 'ASC',
                    ),
                    'description' => esc_html__( 'Select Order Type ', 'megastore' ),
                    'edit_field_class'=>'vc_col-sm-6 vc_column',
                ),
                array(
                    "type"          => "attach_image",
                    "heading"       => esc_html__("Banner",'megastore'),
                    "param_name"    => "image_ft",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array('list-home16','list-home11',"cat-tab-home3","list-home7-small","sale-home6","tab-home9"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Banner Link",'megastore'),
                    "param_name"    => "image_link",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array('list-home16','list-home11',"cat-tab-home3","list-home7-small","sale-home6","tab-home9"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Title info top",'megastore'),
                    "param_name"    => "title_intop",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Description info top",'megastore'),
                    "param_name"    => "des_intop",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Link info top",'megastore'),
                    "param_name"    => "link_intop",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Title info middle",'megastore'),
                    "param_name"    => "title_inmid",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Description info middle",'megastore'),
                    "param_name"    => "des_inmid",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Link info middle",'megastore'),
                    "param_name"    => "link_inmid",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Title info bottom",'megastore'),
                    "param_name"    => "title_inbot",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Description info bottom",'megastore'),
                    "param_name"    => "des_inbot",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Link info bottom",'megastore'),
                    "param_name"    => "link_inbot",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "dropdown",
                    "heading"       => esc_html__("Banner Position",'megastore'),
                    "param_name"    => "banner_pos",
                    "value"         => array(
                        esc_html__("Banner Left",'megastore')   => 'banner-left',
                        esc_html__("Banner Right",'megastore')   => 'banner-right',
                        ),
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("list-home16"),
                        )
                ),
                array(
                    "type"          => "attach_image",
                    "heading"       => esc_html__("Banner 2",'megastore'),
                    "param_name"    => "image_ft2",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("tab-home9"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Banner Link 2",'megastore'),
                    "param_name"    => "image_link2",
                    "dependency"    => array(
                        "element"       => "style",
                        "value"         => array("tab-home9"),
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Size Thumbnail",'megastore'),
                    "param_name"    => "size",
                    "group"         => esc_html__("Advanced",'megastore'),
                    'description' => esc_html__( 'Enter site thumbnail to crop. [width]x[height]. Example is 300x300', 'megastore' ),
                ),
                array(
                    "type"          => "dropdown",
                    "heading"       => esc_html__("Show extra info",'megastore'),
                    "param_name"    => "extra_info",
                    "group"         => esc_html__("Advanced",'megastore'),
                    "value"         => array(
                        esc_html__("Yes",'megastore') => 'yes',
                        esc_html__("No",'megastore') => 'no',
                        )
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Item",'megastore'),
                    "param_name"    => "item",
                    "group"         => esc_html__("Advanced",'megastore'),
                ),
                array(
                    "type"          => "textfield",
                    "heading"       => esc_html__("Item Responsive",'megastore'),
                    "param_name"    => "item_res",
                    "group"         => esc_html__("Advanced",'megastore'),
                    'description' => esc_html__( 'Enter item for screen width(px) format is width:value and separate values by ",". Example is 0:2,600:3,1000:4. Default is auto.', 'megastore' ),
                ),
                array(
                    "type"          => "dropdown",
                    "heading"       => esc_html__("Autoplay",'megastore'),
                    "param_name"    => "autoplay",
                    "group"         => esc_html__("Advanced",'megastore'),
                    "value"         => array(
                        esc_html__("False",'megastore') => 'false',
                        esc_html__("True",'megastore') => 'true',
                        )
                ),
                array(
                    "type"          => "dropdown",
                    "heading"       => esc_html__("Loop",'megastore'),
                    "param_name"    => "loop",
                    "group"         => esc_html__("Advanced",'megastore'),
                    "value"         => array(
                        esc_html__("True",'megastore') => 'true',
                        esc_html__("False",'megastore') => 'false',
                        )
                ),
            )
        ));
    }
}
}