<?php 
	$number    		= isset( $instance['numberposts'] ) ? intval($instance['numberposts']) : 5;
	global $wpdb;
	global $post;
?>
<?php do_action( 'before' ); ?>
<?php if ( !class_exists( 'WooCommerce' ) ) { 
	return "Please active woocommerce plugin first!";
}

	$args = array( 'post_type' => 'product', 'posts_per_page' => $number );
	$args['meta_query'] = array();					
	if( sw_woocommerce_version_check( '3.0' ) ){	
		$args['tax_query'][] = array(						
			'taxonomy' => 'product_visibility',
			'field'    => 'name',
			'terms'    => 'featured',
			'operator' => 'IN',	
		);
	}else{
		$default['meta_query'] = array(
			args(
				'key' 		=> '_featured',
				'value' 	=> 'yes'
			)					
		);				
	}

	$loop = new WP_Query( $args );
	$i = 0;
	$j = 0;
	$k = 0;
	
if ( $loop->have_posts() ) {
?>
<div id="<?php echo esc_attr( $widget_id ); ?>" class="sw-feature-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;
		wp_reset_postdata();
	?>
	</ul>
</div>
<?php } ?>
