<?php 
	global $woocommerce;
	$number    		= isset( $instance['numberposts'] ) ? intval($instance['numberposts']) : 5;
	
	$args = array(
	'post_type'		=> 'product',
	'meta_key'		=> 'recommend_product',
	'meta_value'	=> 'yes',
	'showposts'		=> $number );
	$loop = new wp_query( $args );
	if( $loop -> have_posts() ) {	
?>
	<div id="<?php echo esc_attr( $widget_id ); ?>" class="sw-recommend-product">
		<ul class="list-unstyled">
			<?php 
			while ($loop->have_posts()) : $loop->the_post();
			global $product, $post;
			$rating_count = $product->get_rating_count();
			$review_count = $product->get_review_count();
			$average      = $product->get_average_rating();
			?>
			<li class="clearfix">
				<div class="item-img">
					<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>">
						<?php if( has_post_thumbnail() ){  
							echo (get_the_post_thumbnail( $loop->post->ID, 'shop_thumbnail')) ? get_the_post_thumbnail( $loop->post->ID, 'shop_thumbnail') : '<img src="'.get_template_directory_uri().'/assets/img/placeholder/shop_thumbnail.png" alt="No thumb"/>' ;
						}else{ 
							echo '<img src="'.get_template_directory_uri().'/assets/img/placeholder/shop_thumbnail.png" alt="No thumb"/>' ;
						} ?>
					</a>
				</div>
				<div class="item-content">
					<h4><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"><?php the_title(); ?></a></h4>
					<p><?php echo $product->get_price_html(); ?></p>
					<div class="star"><?php echo ( $average > 0 ) ?'<span style="width:'. ( $average*16 ).'px"></span>' : ''; ?></div>				
					<div class="review">
						<span><?php echo $count; ?> <?php esc_html_e(' review(s)', 'furnicom'); ?></span>
					</div>
				</div>
			</li>
			<?php endwhile; ?>
		</ul>
	</div>
<?php
}
?>