<?php
if(get_theme_mod('featured_products_area_disable') != 'on' ){
	?>
	<?php 
		if( get_theme_mod('featured_products_areaTpadding',true) ) {
			$featured_products_areaTpadding = 'padding-top:'.esc_attr(get_theme_mod('featured_products_areaTpadding')).';';
		}
		if( get_theme_mod('featured_products_areaBpadding',true) ) {
			$featured_products_areaBpadding = 'padding-bottom:'.esc_attr(get_theme_mod('featured_products_areaBpadding')).';';
		} 
	?>			
<div class="featuredproducts-area " id="featuredproducts">		  
		<div class="container">
			<?php
					$showStatic = true;
					for( $i = 1; $i < 11; $i++ ){
						$featuredproductsus_page_id = get_theme_mod('featuredproductsus_page_icon'.$i); 
						if(!empty($featuredproductsus_page_id)){
							$showStatic = false;
							break;
						}
					}
					$feature_title = get_theme_mod('feature_title', 'Featured Products');
					$featuredproductsubtitle = get_theme_mod('featuredproductsubtitle', 'Discover the Southern Flavors Within Our Wines');
			?>
			<div class="row justify-content-center">
          <div class="section-title">
              <h2><?php echo ($feature_title);  ?></h2>
                  <?php if( $featuredproductsubtitle){ ?>
                      <div class="titlicnbx">
                          <p><?php echo ($featuredproductsubtitle);  ?></p>
                      </div>
                  <?php } ?>
          </div>    
      </div> 
			<div class="featuredproductsus-post-wrap">
				<div class="featuredproductsus-post-boxes row">
					<div class="owl-carousel owl-theme"> 
						<?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;
				    					$product_id = $product->get_id();
											//$wishlist_url = esc_url(add_query_arg('add_to_wishlist', $product_id));
							        $sale_text = get_post_meta(get_the_ID(), '_custom_product_salenew_field', true);
							        $discount_text = get_post_meta(get_the_ID(), '_custom_product_discount_field', true);
						?>
						<div class="item featuredproductsbx wow zoomIn" data-wow-duration="1s">
							<div class="featuredproductsus-single" >
								<div class="featuredproducts-box"> 
									<div class="hi-icon">
										<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" 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="featured products" />'; 
			    							?>
										</a>
									</div>
									<div class="product_label">
				              <?php  if (!empty($sale_text)) : ?>
					                <div class="product-discount-data">
													<span class="product-discount"><?php echo ($sale_text);  ?></span>
												</div>
											<?php endif ?>
											<?php  if (!empty($discount_text)) : ?>
							          <div class="product-discount-data">
														<span class="product-discount"><?php echo ($discount_text);  ?></span>
												</div>
											<?php endif ?>
									</div>
									<div class="featured-icons">
											<div class="featured-list tooltip-container">
												<?php 
													$user_id = get_current_user_id();
													$product_id = $product->get_id();
													$wishlist = get_user_meta($user_id, 'wishlist', true);
													$button_class = in_array($product_id, (array)$wishlist) ? 'added' : '';
													$nonce = wp_create_nonce('update_wishlist_' . $product_id);

													$wishlist_url = esc_url(add_query_arg(
													    array(
													        'update_wishlist' => $product_id,
													        '_wpnonce' => $nonce
													    )
													));

													echo '<a href="' . $wishlist_url . '" class="add-to-wishlist-button ' . $button_class . '">
													    <span class="spinner"></span>
													    <i class="fa fa-heart' . ($button_class ? '' : '-o') . '" aria-hidden="true"></i>
													    <span class="tooltip-text">' . ($button_class ? 'Added to Wishlist' : 'Add to Wishlist') . '</span>
													</a>'; 
												?>
											</div>
										    <div class="featured-list tooltip-container">
										        <a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" data-quantity="1" class="button product_type_<?php echo esc_attr( $product->get_type() ); ?> add_to_cart_button">
										            <span class="spinner"></span><i class="fa fa-shopping-cart"></i><span class="tooltip-text">Add to Cart</span>
										        </a>
										    </div>
										    <div class="featured-list tooltip-container">
										        <a href="#quick-view-<?php the_id(); ?>" class="quick-view" data-product-id="<?php echo esc_attr( $product->get_id() ); ?>">
										            <span class="spinner"></span><i class="fa fa-eye"></i><span class="tooltip-text">Quick View</span>
										        </a>
										    </div>
										</div>

										<div id="quick-view-<?php the_id(); ?>" class="quick-view-popup">
									    <div class="quick-view-content">
									        <button class="close-quick-view">
									        	<svg viewBox="0 0 28 28" fill="none" >
									        		<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
									        		<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
									        		<g id="SVGRepo_iconCarrier"> <path fill-rule="evenodd" clip-rule="evenodd" d="M5.46967 5.46967C5.76256 5.17678 6.23744 5.17678 6.53033 5.46967L18.5303 17.4697C18.8232 17.7626 18.8232 18.2374 18.5303 18.5303C18.2374 18.8232 17.7626 18.8232 17.4697 18.5303L5.46967 6.53033C5.17678 6.23744 5.17678 5.76256 5.46967 5.46967Z" fill="#000000"></path> 
									        			<path fill-rule="evenodd" clip-rule="evenodd" d="M18.5303 5.46967C18.8232 5.76256 18.8232 6.23744 18.5303 6.53033L6.53035 18.5303C6.23745 18.8232 5.76258 18.8232 5.46969 18.5303C5.17679 18.2374 5.17679 17.7626 5.46968 17.4697L17.4697 5.46967C17.7626 5.17678 18.2374 5.17678 18.5303 5.46967Z" fill="#000000"></path> 
									        		</g>
									        	</svg>
									        </button>
									        <div class="product-details">
									        	<div class="row">
									        		<div class="col-lg-4">
									        			<div class="product-image">
											                <?php
											                if (has_post_thumbnail($loop->post->ID)) {
											                    echo get_the_post_thumbnail($loop->post->ID, 'shop_single');
											                } else {
											                    echo '<img src="' . get_template_directory_uri() . '/images/default.png" alt="featured products" />';
											                }
											                ?>
											            </div>
									        		</div>
									        		<div class="col-lg-8">
									        			<h2><?php the_title(); ?></h2>
									        			<div class="product-price">
											                <?php echo $product->get_price_html(); ?>
											            </div>
									        			 <div class="product-description">
											                <?php the_content(); ?>
											            </div>
											            <div class="product-button">
													            <div class="product-add-to-cart">
													              <a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" data-quantity="1" class="button product_type_<?php echo esc_attr( $product->get_type() ); ?> add_to_cart_button">
																            <i class="fa fa-shopping-cart"></i><span class="tooltip-text">Add to Cart</span>
																        </a>
													            </div>
													            <div class="product-wishlist">
													                <a href="<?php echo $wishlist_url; ?>" class="add-to-wishlist-button <?php echo $button_class; ?>">
																			        <!-- <span class="spinner"></span> -->
																			        <i class="fa fa-heart<?php echo $button_class ? '' : '-o'; ?>" aria-hidden="true"></i>
																			        <span class="tooltip-text"><?php echo $button_class ? 'Added To Wishlist' : 'Add To Wishlist'; ?></span>
																			    </a>
													            </div>
													        </div>
									        		</div>
									        	</div>
									        </div>
									    	</div>
											</div>
								</div> 
								<div class="featuredproducts-area-data">
									<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
										<h4 class="inner-area-title"><?php the_title();?></h4></a>
									<div class="price"><?php echo $product->get_price_html(); ?></div>
								</div>				 
							</div>
						</div>
						<?php					
						endwhile; 
							}else{
						?>
						<div class="item  featuredproductsbx wow zoomIn" data-wow-duration="1s">
							<div class="featuredproductsus-single" >
								<div class="featuredproducts-box"> 
									<div class="hi-icon">
										<a href="#">
											<img class="img-responsive" src="<?php echo esc_url(get_template_directory_uri().'/images/feature.png');?>" alt="featured products" />
											<div class="skewd"></div>	
										</a>
									</div>
								</div> 
								<div class="featuredproducts-area-data">
									<a href="#"><h4 class="inner-area-title">Wooden Mirror</h4></a>
									<div class="price">$159.00</div>
									<div class="fea-btn">
										<a href="#">
											<span>Add To Cart</span>
											<span><i class="fa fa-shopping-cart" aria-hidden="true"></i></span>
										</a>
									</div>
								</div>				 
							</div>
						</div>
						<?php }
							//wp_reset_query(); 
						}
							?>
						</div>	
				</div>
			</div>
		</div>
	</div>
<script>
    
</script>
<?php }  