<?php
/**
 * Template to show the content of Pet Sale section
 *
 * @package vw_book_store_pro
 */ 
$about_section = get_theme_mod( 'vw_book_store_pro_latest_collection_section_enable' );
if ( 'Disable' == $about_section ) {
  return;
}
/*About us*/
$img_bg = get_theme_mod('vw_book_store_pro_latest_collection_bgimage_attachment');
if( get_theme_mod('vw_book_store_pro_latest_collection_bgcolor','') ) {
  $about_backg = 'background-color:'.esc_attr(get_theme_mod('vw_book_store_pro_latest_collection_bgcolor','')).';';
}elseif( get_theme_mod('vw_book_store_pro_latest_collection_bgimage','') ){
  $about_backg = 'background-image:url(\''.esc_url(get_theme_mod('vw_book_store_pro_latest_collection_bgimage')).'\')';
}else{
  $about_backg = '';
}
?>
<section id="latest_collection" style="<?php echo esc_attr($about_backg); ?>" class="wow fadeInUp delay-3000 animated <?php echo esc_attr($img_bg); ?>" data-wow-duration="2s">
  <div class="container latest_col">
    <?php if ( class_exists( 'WooCommerce' ) ) {?>
      <div class="products custom_items ml-0">
        <div class="collection-content">
          <div class="collection-inner">
            <?php if(get_theme_mod('vw_book_store_pro_latest_collection_title',true) != ''){?>
              <h4 class="text-uppercase"><?php echo esc_html(get_theme_mod('vw_book_store_pro_latest_collection_title')); ?></h4>
            <?php }?>
            <?php if(get_theme_mod('vw_book_store_pro_latest_collection_sale',true) != ''){?>
              <h3 class="text-uppercase"><?php echo esc_html(get_theme_mod('vw_book_store_pro_latest_collection_sale')); ?></h3>
            <?php }?>
            <?php if(get_theme_mod('vw_book_store_pro_latest_collection_desc',true) != ''){?>
              <p><?php echo (get_theme_mod('vw_book_store_pro_latest_collection_desc')); ?></p>
            <?php }?>
            <?php if( get_theme_mod('vw_book_store_pro_latest_collection_btn',true) != ''){ ?>
              <a class="theme_green_button d-inline-block mt-2" href="<?php echo esc_url(get_theme_mod('vw_book_store_pro_latest_collection_btn_url')); ?>"><?php echo esc_html(get_theme_mod('vw_book_store_pro_latest_collection_btn')); ?></a>
            <?php } ?>
          </div>
        </div>
        <div class="row">
          <?php
            $args = array( 
              'post_type' => 'product', 
              'posts_per_page' => 4,
              'product_cat' => get_theme_mod('vw_book_store_pro_latest_collection_category')
            );
          $loop = new WP_Query( $args );
          while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
          <div class="col-lg-6 col-md-6 col-sm-12 col-12 lc_box">
            <div class="latest_product product-content">              
              <div class="row">
                <div class="col-md-5 col-sm-5 col-12 p-0">
                  <div class="latest-thumb">                
                    <?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>
                </div>
                <div class="col-md-7 col-sm-7 col-12 mt-4">
                  <div class="latest-box">
                    <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); ?>"><h5 class="product_head"><?php the_title(); ?></h5></a>
                    <p><?php $excerpt = get_the_excerpt(); echo esc_html(vw_book_store_pro_string_limit_words($excerpt,15)); ?></p>

                    <div class="latest-cart">
                      <?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_add_to_cart( $loop->post, $product ); } ?>
                    </div>
                  </div>
                </div>
              </div>              
            </div>
          </div>
          <?php endwhile; ?>
          <?php wp_reset_query(); ?>
        </div>
      </div>
    <?php } else{ ?>
      <h3 class="text-center"><?php echo esc_html_e('Please install Woocommerce plugin and add your products to enable this section','vw-book-store-pro')?></h3>
    <?php }?>
  </div>
</section>