<?php if ( true == get_theme_mod( 'chocolate_store_slide_on_off', 'on' ) ) : ?>

<?php $chocolate_store_slide_count = get_theme_mod('chocolate_store_slide_count'); ?>

<section id="home_slider">
	<div class="slider-section">
		<div class="owl-carousel">
			<?php for ($i=1; $i <= $chocolate_store_slide_count; $i++) {
				$chocolate_store_slider_image = get_theme_mod('chocolate_store_slider_image'.$i);
				$chocolate_store_slider_short_heading = get_theme_mod('chocolate_store_slider_short_heading'.$i);
				$chocolate_store_slider_heading = get_theme_mod('chocolate_store_slider_heading'.$i);
				$chocolate_store_slider_button_link = get_theme_mod('chocolate_store_slider_button_link'.$i); 
				$chocolate_store_slider_button_text = get_theme_mod('chocolate_store_slider_button_text'.$i); 
				?>

				<div class="slider_main_box wow fadeInDown" data-wow-duration="2s">
					<?php if ( ! empty( $chocolate_store_slider_image ) ) : ?>
						<img src="<?php echo esc_url( $chocolate_store_slider_image ); ?>">
						<div class="slider_content_box">
							<?php if ( ! empty( $chocolate_store_slider_short_heading ) ) : ?>
								<h3><?php echo esc_html( $chocolate_store_slider_short_heading ); ?></h3>
							<?php endif; ?>
							<?php if ( ! empty( $chocolate_store_slider_heading ) ) : ?>
								<h2><?php echo esc_html( $chocolate_store_slider_heading ); ?></h2>
							<?php endif; ?>
							<div class="slider_button my-4">
								<?php if ( ! empty( $chocolate_store_slider_button_link ) || ! empty( $chocolate_store_slider_button_text ) ): ?>
									<a class="button1" href="<?php echo esc_url( $chocolate_store_slider_button_link ); ?>"><?php echo esc_html( $chocolate_store_slider_button_text ); ?></a>
								<?php endif; ?>
							</div>
						</div>
					<?php endif; ?>
				</div>
			<?php } ?>
		</div>
	</div>
	<?php if ( get_theme_mod('chocolate_store_slider_product_category') ) : ?>
		<div class="product-main wow zoomIn" data-wow-duration="2s">
			<div class="slider-product-section">
				<?php 
				$chocolate_store_catData = get_theme_mod('chocolate_store_slider_product_category','');
				if ( class_exists( 'WooCommerce' ) ) {
				$chocolate_store_args = array(
				'post_type' => 'product',
				'posts_per_page' => 3,
				'product_cat' => $chocolate_store_catData,
				'order' => 'ASC'
				); ?>
				<div class="owl-carousel">
					<?php $loop = new WP_Query( $chocolate_store_args );
					while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>        	
					<div class="tab-product text-center">
						<div class="product-image box">
							<figure class="mb-0">
							<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.esc_url(wc_placeholder_img_src()).'" />'; ?>
						</figure>
						</div>
						<div class="product-details py-3">
							<h5 class="product-text mb-2"><a href="<?php echo esc_url(get_permalink( $loop->post->ID )); ?>"><?php the_title(); ?></a></h5>
						<?php 
							$product = wc_get_product( get_the_ID() ); // Get the current product
							$product_categories = wp_get_post_terms( $product->get_id(), 'product_cat' ); // Get product categories

							if ( ! empty( $product_categories ) ) {
								echo '<span class="woo-cat ">' . esc_html( $product_categories[0]->name ) . '</span>'; // Display the first category
							}
							?>
						<?php if( $product->is_type( 'simple' ) ){ woocommerce_template_loop_rating( $loop->post, $product ); } ?>
							<h6 class="<?php echo esc_attr( apply_filters( 'woocommerce_product_price_class', 'price' ) ); ?> mb-4"><?php echo $product->get_price_html(); ?></h6>
						<div class="box-content intro-button mt-2">
							<?php if( $product->is_type( 'simple' ) ) { woocommerce_template_loop_add_to_cart(  $loop->post, $product );} ?>
						</div>
						</div>
					</div>
					<?php endwhile; wp_reset_postdata(); ?>
					<?php } ?>
				</div>
			</div>
		</div>
	<?php endif; ?>
</section>

<?php endif; ?>