<?php

if ( ! get_theme_mod( 'aster_ebooks_enable_service_section', false ) ) {
	return;
}

$aster_ebooks_args = '';

aster_ebooks_render_service_section( $aster_ebooks_args );

/**
 * Render Service Section.
 */
function aster_ebooks_render_service_section( $aster_ebooks_args ) { ?>
		<section id="aster_ebooks_trending_section" class="asterthemes-frontpage-section trending-section trending-style-1">
		<?php
		if ( is_customize_preview() ) :
			aster_ebooks_section_link( 'aster_ebooks_service_section' );
		endif;

		$aster_ebooks_trending_product_heading = get_theme_mod( 'aster_ebooks_trending_product_heading', '' );
		?>
		<div class="asterthemes-wrapper">
			<?php if ( ! empty( $aster_ebooks_trending_product_heading ) ) { ?>
				<div class="header-contact-inner">
					<h3><?php echo esc_html( $aster_ebooks_trending_product_heading ); ?></h3>
				</div>
			<?php } ?>
			<?php $aster_ebooks_catData = get_theme_mod('aster_ebooks_trending_product_category','');
      if ( class_exists( 'WooCommerce' ) ) {
        $aster_ebooks_args = array(
          'post_type' => 'product',
          'posts_per_page' => 100,
          'product_cat' => $aster_ebooks_catData,
          'order' => 'ASC'
        );?>
        <div class="product-box"> 
	        <?php $aster_ebooks_loop = new WP_Query( $aster_ebooks_args );
	        while ( $aster_ebooks_loop->have_posts() ) : $aster_ebooks_loop->the_post(); global $product; ?>
	          <div class="tab-product">
            	<figure>
              	<?php if (has_post_thumbnail( $aster_ebooks_loop->post->ID )) echo get_the_post_thumbnail($aster_ebooks_loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(wc_placeholder_img_src()).'" />'; ?>
              	<?php if ( has_post_thumbnail() ) { ?>
                    <?php woocommerce_show_product_sale_flash( $product ); ?>
                <?php }?>
                <div class="box-content intro-button">
              		<?php if( $product->is_type( 'simple' ) ) { woocommerce_template_loop_add_to_cart(  $aster_ebooks_loop->post, $product );} ?>
          			</div>
              </figure>
        			<?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $aster_ebooks_loop->post, $product ); } ?>
          			<h5 class="product-text"><a href="<?php echo esc_url(get_permalink( $aster_ebooks_loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
        			<h6 class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>"><?php echo $product->get_price_html(); ?></h6>
	          </div>
	        <?php endwhile; wp_reset_postdata(); ?>
	      </div>
      <?php } ?>
		</div>
	</section>
	<?php
}