<?php
if ( ! get_theme_mod( 'handmade_craft_enable_product_section', false ) ) {
	return;
}

$handmade_craft_args = '';

handmade_craft_render_service_section( $handmade_craft_args );

/**
 * Render Product Section.
 */
function handmade_craft_render_service_section( $handmade_craft_args ) { ?>
		<section id="handmade_craft_trending_section" class="asterthemes-frontpage-section product-section trending-style-1">
		<?php
		if ( is_customize_preview() ) :
			handmade_craft_section_link( 'handmade_craft_service_section' );
		endif;

		$handmade_craft_trending_product_heading = get_theme_mod( 'handmade_craft_trending_product_heading');
		$handmade_craft_product_view_button_text = get_theme_mod( 'handmade_craft_product_view_button_text');
		$handmade_craft_product_view_button_url = get_theme_mod( 'handmade_craft_product_view_button_url');
		?>
		<div class="asterthemes-wrapper">
			<?php if ( ! empty( $handmade_craft_trending_product_heading ) ) { ?>
				<div class="header-contact-inner">
					<h3><?php echo esc_html( $handmade_craft_trending_product_heading ); ?></h3>
				</div>
			<?php } ?>
			<?php $handmade_craft_catData = get_theme_mod('handmade_craft_trending_product_category','');
			if ( class_exists( 'WooCommerce' ) ) {
				$handmade_craft_args = array(
				'post_type' => 'product',
				'posts_per_page' => -1,
				'product_cat' => $handmade_craft_catData,
				'order' => 'ASC'
				);?>
				<div class="product-box"> 
					<div class="owl-carousel">
						<?php $handmade_craft_loop = new WP_Query( $handmade_craft_args );
						while ( $handmade_craft_loop->have_posts() ) : $handmade_craft_loop->the_post(); global $product; ?>
							<div class="tab-product wow zoomIn delay-3000">
								<figure style="position:relative;">
									<?php
									// Show Sale Badge
									if ( $product->is_on_sale() ) {
										echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">Sale!</span>', $product );
									}

									// Product Image
									if ( has_post_thumbnail( $handmade_craft_loop->post->ID ) ) {
										echo get_the_post_thumbnail( $handmade_craft_loop->post->ID, 'shop_catalog' );
									} else {
										echo '<img src="'.esc_url( wc_placeholder_img_src() ).'" />';
									}
									?>
								</figure>
								<div class="product-content-box">
									<h5 class="product-text"><a href="<?php echo esc_url(get_permalink( $handmade_craft_loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
									<div class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?>">
										<?php echo $product->get_price_html(); ?>
									</div>
								</div>
								<div class="box-content intro-button addcart">
									<?php if( $product->is_type( 'simple' ) ) { woocommerce_template_loop_add_to_cart(  $handmade_craft_loop->post, $product );} ?>
								</div>
							</div>
						<?php endwhile; wp_reset_postdata(); ?>
					</div>
					<?php if ( ! empty( $handmade_craft_product_view_button_text ) ) { ?>
						<div class="products-view-btn">
							<a href="<?php echo esc_url( $handmade_craft_product_view_button_url ); ?>" class="asterthemes-button"><?php echo esc_html( $handmade_craft_product_view_button_text ); ?> <i class="fas fa-arrow-right"></i></a>
						</div>
					<?php } ?>
				</div>
			<?php } ?>
		</div>
	</section>
	<?php
}