<?php
/**
 * @package LZ Restaurant Premium
 */
if(get_theme_mod('lz_fitness_premium_top_product_section_disable') != 'on' ){
    wp_enqueue_script('slider', get_template_directory_uri().'/js/slider.js', array(), '1.1', true);
    ?>
    <section id="top-product-section" class="ht-section">
        <div class="lightbox">
            <div class="top-product-box">
                <div class="wow fadeInUp" data-wow-duration="1s">
                    <?php
                    $showStatic = true;
                    for( $i = 1; $i < 4; $i++ ){
                        $lz_fitness_top_product_page_id = get_theme_mod('lz_fitness_top_product_page'.$i); 
                        if(!empty($lz_fitness_top_product_page_id)){
                            $showStatic = false;
                            break;
                        }
                    }
             
                    $lz_fitness_top_product_title = get_theme_mod('lz_fitness_top_product_title', 'TOPSELLAR'); 
                      
                    ?>
                    <div class="row">
                        <div class="ht-section-title-tagline">
                            <h2 class="ht-section-title lz-topsellar-heading">
                                <?php
                                if(!empty($lz_fitness_top_product_title))    {
                                    echo ($lz_fitness_top_product_title);
                                } ?>
                            </h2>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="row">
                        <button class="slide-prev ctrl-btn pro-prev fa fa-chevron-left"></button>
                            <button class="ctrl-btn pro-next fa fa-chevron-right slide-next"></button>
                        <!-- Wrapper for slides -->
                        <div class="slider" id="slider">
                            <div class="slides" id="slide">
                      
                                <?php
                                if(function_exists('woocommerce_template_loop_add_to_cart') && function_exists('WC')){

                                     $categories = get_theme_mod('lz_fitness_product_tab_categories');
                                    $args = array(
                                //'number' => 12,
                                'orderby' => 'name',
                                'posts_per_page' => -1, 
                                'order' => 'asc',
                                'hide_empty' => false,
                                'include' => $categories
                            );
                                    $product_categories = get_terms('product_cat', $args);
                                    $i = 0;
                                    if(function_exists('get_woocommerce_term_meta')){
                                    foreach ($product_categories as $cat) {
                                    if(!empty($cat)){
                                    ?>
                                    <h2><?php echo !empty($cat->name)?$cat->name:''; ?></h2>
                                    <?php
                            $i = 0;
                            $args = array( 'post_type' => 'product', 'posts_per_page' => 12,  'orderby' =>'name','order' => 'asc' );
                                    
                                    if(!empty($cat->slug)){
                                        $args['product_cat']= $cat->slug;
                                        $product = new stdClass();
                                        $loop = new WP_Query( $args );
                                        while ( $loop->have_posts() ) : $loop->the_post(); global $product; 
                                            ?>
                                        <div class="col-md-3 slide-item topsellar padding0"> 
                                            <div id="topsellar-porduct">
                                                <div class="pro-img text-center">
                                                    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                                        <?php if (has_post_thumbnail( $loop->post->ID )) 
                                                        echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
                                                        else
                                                            echo '<img src="'.get_template_directory_uri().'/images/default.png" alt="Placeholder" width="100%" height="200px" />'; ?>  
                                                    </a>
                                                </div>
                                                <div class="ht-topsellar-social-id">
                                                   
                                                    <?php
                                                    $product->is_icon = true;
                                                    woocommerce_template_loop_add_to_cart( $product ); ?>
                                                    <?php //do_action( 'woocommerce_after_shop_loop_item' ); ?>
                                                    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><i class="fa fa-eye"></i></a>
                                                   
                                                </div>
                                                <div class="topsellar-products-title-wrap">
                                                    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">   
                                                        <h6><?php the_title(); ?></h6></a>
                                                        <span class="price"><?php echo $product->get_price_html(); ?></span>
                                                    </div>
                                                </div>
                                            </div><!-- /span3 -->
                                            <?php
                                        endwhile; 
                                    }
                                }

                            }
                        }else{ ?>
                                    <div class="alert alert-warning text-center">
                                        <strong>Sorry, no recent products to show.</strong>
                                    </div>
                                    <?php
                                }
                                ?>
                            
                                <?php
                                wp_reset_query(); 

                            }else{ ?>
                            <div class="alert alert-warning text-center">
                                Kindly Install or Activate the WooCommerce plugin.
                            </div>
                            <?php
                        }?>
                    </div>
                </div><!-- /row-fluid -->
            </div>
        </div>
    </div>
    <div class="clearfix"></div>

</div>
</section>
<?php }