<?php
/**
 * Template to show the content of Pet Sale section
 *
 * @package vw_book_store_pro
 */ 
$about_section = get_theme_mod( 'vw_book_store_pro_radio_trending_product_enable' );
if ( 'Disable' == $about_section ) {
  return;
}
/*About us*/
$img_bg = get_theme_mod('vw_book_store_pro_trending_product_image_bg');
if( get_theme_mod('vw_book_store_pro_trending_product_bgcolor','') ) {
  $about_backg = 'background-color:'.esc_attr(get_theme_mod('vw_book_store_pro_trending_product_bgcolor','')).';';
}elseif( get_theme_mod('vw_book_store_pro_trending_product_bgimage','') ){
  $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('vw_book_store_pro_trending_product_bgimage')).'\')';
}else{
  $about_backg = '';
}
?>
<section id="trending_product" style="<?php echo esc_attr($about_backg); ?>" class="wow slideInUp delay-3000 animated  <?php echo esc_attr($img_bg); ?>" data-wow-duration="2s" >
  <div class="container">
    <?php if(get_theme_mod('vw_book_store_pro_product_title',true) != '' || get_theme_mod('vw_book_store_pro_trending_product_btn',true != '')){ ?>
      <div class="section-title d-inline-block w-100">
        <?php if(get_theme_mod('vw_book_store_pro_product_title',true != '')){ ?>
            <h3 class="float-left align-self-end"><?php echo esc_html(get_theme_mod('vw_book_store_pro_product_title')); ?></h3>
        <?php }
          
        if(get_theme_mod('vw_book_store_pro_trending_product_btn',true != '')){ ?>  
          <a href="<?php echo esc_url(get_theme_mod('vw_book_store_pro_trending_product_btn_link')); ?>"class="theme_green_button float-right"><?php echo esc_html(get_theme_mod('vw_book_store_pro_trending_product_btn')); ?><i class="<?php echo esc_html(get_theme_mod('vw_book_store_pro_trending_product_btn_icon')); ?>"></i></a>
        <?php } ?>
      </div>
    <?php } ?>
    <?php if ( class_exists( 'WooCommerce' ) ) {?>
      <div class="products custom_items ml-0">
        <div class="row">
          <?php
          $args = array( 
          'post_type' => 'product', 
          'posts_per_page' => get_theme_mod('vw_book_store_pro_trending_product_number'),
          'product_cat' => get_theme_mod('vw_book_store_pro_trending_products_category')
          );
          $loop = new WP_Query( $args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
          <div class="col-lg-3 col-md-6 col-sm-6 trending_col"> 
            <div class="inner_product product-content"> 
              <a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
              <div class="product-thumb">
                <div class="product-sale"><?php woocommerce_show_product_sale_flash( $post, $product ); ?></div>
                <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(woocommerce_placeholder_img_src()).'" alt="Placeholder" />'; ?>
              <div class="custom-product-price"><?php echo $product->get_price_html(); ?></div>
              </div>
              <h5 class="product_head"><?php the_title(); ?></h5>
              <p><?php $excerpt = get_the_excerpt(); echo esc_html(vw_book_store_pro_string_limit_words($excerpt,8)); ?></p>
              </a>
               <div class="rating_comment text-center">
                <div class="product-rating"> 
                    <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
                </div>
                <div class="comment-value">
                    <?php $rating_count = $product->get_rating_count(); 
                    if ($rating_count > 0) {
                        echo '('. $rating_count.')';
                      }
                    ?>
                </div>
              </div>
              <div class="custom_cart">
                <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>
              </div>
            </div>
          </div>
          <?php endwhile; ?>
          <?php wp_reset_query(); ?>
        </div>
      </div>
    <?php } else{ ?>
      <h3 class="text-center"><?php esc_html_e('Please install Woocommerce plugin and add your products to enable this section','vw-book-store-pro')?></h3>
    <?php }?>
  </div>
</section>