<?php
/**
 *
 * Product grid section
 *
 * @author      CodeGearThemes
 * @category    WordPress
 * @package     Acoustics
 * @version     1.0.0
 *
 */
if(! class_exists('Woocommerce')) {
	return;
}

$acoustics_product_collection = absint( get_theme_mod( 'acoustics_bestseller_collection' , 0 ) );
if( $acoustics_product_collection > 0 ): ?>
	<div id="section_bestseller_grid" class="section-products block-products-grid" type="bestseller">
		<div class = "<?php echo esc_attr( apply_filters( 'acoustics_container_class', 'container' ) ); ?>">
			<div class="section-heading">
				<h3 class="section-title h4">
					<span><?php esc_html_e( 'Best Sellers', 'acoustics' ); ?></span>
				</h3>
			</div>
			<?php
			if( $acoustics_product_collection){
	            $args = array(
	                'post_type' => 'product',
	                'posts_per_page' => 9,
	                'tax_query' => array(
						array(
		                    'taxonomy' => 'product_cat',
		                    'field' => 'term_id',
		                    'terms' => $acoustics_product_collection
						)
	                  )
	                );
					$acoustics_product_query = new WP_Query( $args );
					if( $acoustics_product_query->have_posts() ) { ?>
						<div class="woocommerce">
							<div class="row products products-grid columns clearfix">
								<?php
								while( $acoustics_product_query->have_posts() ) {
									$acoustics_product_query->the_post();
									wc_get_template_part( 'content', 'product' );
								} ?>
							</div>
							<div class="owl-nav owl-nav-bestseller">
								<span role="presentation" class="owl-prev-bestseller" aria-lable="<?php esc_attr_e( 'Previous slide', 'acoustics' ) ?>"></span>
								<span role="presentation" class="owl-next-bestseller" aria-lable="<?php esc_attr_e( 'Next slide', 'acoustics' ) ?>"></span>
							</div>
						</div>
				   	<?php }
					wp_reset_postdata();
				}else{ ?>
					<div class="no-product"><?php esc_html_e( 'No category selected','acoustics' ); ?> </div>
				<?php
			} ?>
		</div>
	</div>
	<?php
endif;
