<?php
if ( class_exists( 'WooCommerce' ) ) {
$leatherhouse_woocommerce_disabled       = get_theme_mod( 'leatherhouse_woocommerce_disabled', true );
	$leatherhouse_woocommerce_area_title     = get_theme_mod( 'leatherhouse_woocommerce_area_title', 'FEATURED PRODUCTS' );
	$leatherhouse_woocommerce_area_des       = get_theme_mod( 'leatherhouse_woocommerce_area_des', '' );
	$leatherhouse_woocommerce_container_size = get_theme_mod( 'leatherhouse_woocommerce_container_size', 'container-full' );
	// $leatherhouse_woocommerce_content        = get_theme_mod( 'leatherhouse_woocommerce_content', leatherhouse_WOOCOMMERCE_DEFAULT_CONTENT );
	if ( true === $leatherhouse_woocommerce_disabled ) : ?>
	<section id="woocommerce-section" class="woocommerce-section av-py-default woocommerce-home shapes-section">
		<div class="<?php echo esc_attr( $leatherhouse_woocommerce_container_size ); ?>">
			<?php if ( ! empty( $leatherhouse_woocommerce_area_title ) || ! empty( $leatherhouse_woocommerce_area_des ) ) : ?>
					<div class="av-columns-area">
						<div class="av-column-12">
							<div class="heading-default text-center wow">
								<?php if ( ! empty( $leatherhouse_woocommerce_area_title ) ) : ?>
									<h3><?php echo wp_kses_post( $leatherhouse_woocommerce_area_title ); ?></h3>
								<?php endif; ?>
								<?php if ( ! empty( $leatherhouse_woocommerce_area_des ) ) : ?>
									<p><?php echo wp_kses_post( $leatherhouse_woocommerce_area_des ); ?></p>
								<?php endif; ?>	
							</div>
						</div>
					</div>
			<?php
			endif;

			$args = array(
				'posts_per_page' => 4,
				'meta_key' => 'total_sales',
				'orderby' => 'meta_value_num',
				'order' => 'DESC',
				'post_type' => 'product',
				'post_status' => 'publish',
			);
			?>
			<div class="best-selling-products">
				<div class="av-columns-area">
						<?php
						$loop = new WP_Query( $args );
						while ( $loop->have_posts() ) :
							$loop->the_post();
							global $product;
							?>
							<div class="av-column-3 av-md-column-6">
								<article class="post-items">

									<?php if ( has_post_thumbnail() ) { ?>
										<a href="<?php echo esc_url( get_permalink() ); ?>" class="post-hover">
											<img class="img-responsive" src="<?php echo the_post_thumbnail_url(); ?>">
										</a>
									<?php } ?>
									<div class="bs-product-content">
										<h5 class="entry-title">
											<a  href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a>
										</h5>
										<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
										<p class="price"><?php echo $product->get_price_html(); ?></p>
									</div>

								</article>
							</div>
						<!-- Woocommerce-module>
							<?php if ( $product->is_on_sale() ) : ?>
								<?php echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . esc_html__( 'On Sale!', 'leather-house' ) . '</span>', $loop->post, $product ); ?>
							<?php endif; ?>
							<figure class="woocommerce-avatar">
								<a href="<?php the_permalink(); ?>">
									<img class="img-responsive" src="<?php echo the_post_thumbnail_url(); ?>">
								</a>
								<figcaption>
									<p class="price"><?php echo $product->get_price_html(); ?></p>
									<h5 class="entry-title">
										<a  href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a>
									</h5>
									<a href="<?php echo get_permalink(); ?>" class="woo-product-view"><i class="fas fa-eye"></i> <?php esc_html_e( 'View' , 'leather-house' ); ?></a>
									<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
								</figcaption>
							</figure>
						-->
						<?php endwhile; ?>
						<?php
						wp_reset_postdata();
						?>
				</div>
			</div>
		</div>
	</section>
	<?php
	endif;
	?>
	<?php
}