<?php
/**
 *
 * @package LZ Premium
 */
if(get_theme_mod('lz_fitness_premium_featured_product_section_disable') != 'on' ){?>
 
	<section id="featured-product-section" class="ht-section">
		<?php if( get_theme_mod('cds_featureprod_curvedisplay','show' ) == 'show') :
			?>
		<div class="section-waveshape">
			<svg class="header-separator-svg header-separator-svg__waves_svg_separator" xmlns="http://www.w3.org/2000/svg" version="1.0" width="1200" fill="#f1f2f4" height="30" viewBox="0 0 1200 30" preserveAspectRatio="none"><path d="M0,0S1.209,1.508,200.671,7.031C375.088,15.751,454.658,30,600,30V0H0ZM1200,0s-90.21,1.511-200.671,7.034C824.911,15.751,745.342,30,600,30V0h600Z"></path></svg>
		</div>
		<?php endif ?>	

		<div class="container">
		
		<div class="featuredproductbox">
			<div class="featuredproduct-box">
				
					<?php
					$showStatic = true;
					for( $i = 1; $i < 4; $i++ ){
						$lz_fitness_featured_product_page_id = get_theme_mod('lz_fitness_featured_product_page'.$i); 
						if(!empty($lz_fitness_featured_product_page_id)){
							$showStatic = false;
							break;
						}
					}
					$lz_fitness_featured_product_title = get_theme_mod('lz_fitness_featured_product_title', 'Our Featured Products');
					?>
					<div class="row">
						<div class="ht-section-title-tagline">
							<h2 class="ht-section-title lz-featuredproduct-heading">
								<?php
								if(!empty($lz_fitness_featured_product_title))	{
									echo ($lz_fitness_featured_product_title);
								} ?>
							</h2>
							<div class="dlab-separator-outer m-b0">
								<div class="dlab-separator text-primary style-icon"><i class="fa fa-birthday-cake"></i></div>
							</div> 
							<div class="clearfix"></div>
						</div>
						<div class="clearfix"></div>
					</div>
					<div class="clearfix"></div>
					<div class="row">
									<?php
					    		if(function_exists('woocommerce_template_loop_add_to_cart') && function_exists('WC')){
					    			$args = array( 'post_type' => 'product', /*'stock' => 1,*/ 'posts_per_page' => 9, 'orderby' =>'date','order' => 'DESC' );
					    			$meta_query   = WC()->query->get_meta_query();
					    			$tax_query   = WC()->query->get_tax_query();
					    			$tax_query[] = array(
					    				'taxonomy' => 'product_visibility',
					    				'field'    => 'name',
					    				'terms'    => 'featured',
					    				'operator' => 'IN',
					    			);
					    			$args = array(
					    				'post_type'   =>  'product',
					    				'stock'       =>  1,
					    				'posts_per_page' => -1, 
					    				'orderby'     =>  'date',
					    				'order'       =>  'DESC',
					    				'meta_query'  =>  $meta_query,
					    				'tax_query'   => $tax_query,
					    			);
					    			$loop = new WP_Query( $args );
					    			if($loop->post_count > 0){
					    				while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
					    				<div class="col-md-3 col-sm-6 featured-product"> 
					    					<div id="recent-porduct">
					    						<div class="pro-img text-center">
					    							<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>">
					    								<?php if (has_post_thumbnail( $loop->post->ID )) 
					    								echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
					    								else
					    									echo '<img src="'.get_template_directory_uri().'/images/default.png" alt="Placeholder" width="100%" height="200px" />'; ?>	
					    							</a>
					    						</div>
					    						<div class="total-product-title-wrap">
					    							<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" target="_blank" title="<?php the_title(); ?>">	
														<h6><?php the_title(); 
														// if(strlen($loop->post->post_title) > 9){
														// 	$title = substr($loop->post->post_title, 0, 10).'...';
														// }else{
														// 	$title = $loop->post->post_title;
														// }
														// echo $title;
														?></h6>
													</a>
													<span class="price"><?php echo $product->get_price_html(); ?></span>
													<div class="clearfix"></div>
													<div class="add-to-cart">
														<?php
														// woocommerce_template_loop_add_to_cart( $loop->single-product, $product );
														woocommerce_template_loop_add_to_cart();
														?>
													</div>
												</div>
											</div>
										</div><!-- /span3 -->
										<?php
									endwhile; 
								}else{ ?>
								<div class="alert alert-warning text-center">
									<strong>Sorry, no featured product to show.</strong>
								</div>
								<?php
							}
							?>
							<!-- </div>-->
							<!-- </div>-->
							<?php
							wp_reset_query(); 
						}else{ ?>
						<div class="alert alert-warning text-center">
							Kindly Install or Activate the WooCommerce plugin.
						</div>
						<?php
					}
?>
				</div>
				<div class="clearfix"></div>
			</div>
			<div class="clearfix"></div>
		</div>
		</div>
		<div class="clearfix"></div>
	</section>
	<script>
	jQuery.noConflict();
	$(function(){
		function featuredproductHeight(){
			var ht = 0;
			$('#featured-product-section .featured-product').each(function(i){
				var tHt = $(this).height();
				if(ht<tHt){
					ht=tHt;
				}
			});
			$('#featured-product-section .featured-product').height(ht+'px');
		}
		featuredproductHeight();
	});
	$( window ).resize(function(){
		featuredproductHeight();
	});
</script>
<?php }