<?php
/*
Theme Designed By: Meysam Hosseinkhani
Email: Meysam98@Gmail.com
Author Website: Hosseinkhani.ir
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}
global $az_data;
global $product;
?>
<div class="rcon">
        <div class="m-product">
            <div class="post-title">
                <h3><i aria-hidden="true" class="<?php echo $az_data['most_viewed_icon']; ?>"></i>
                    <?php echo $az_data['most_viewed_title']; ?>
                </h3>
            </div>
            <div class="owl-carousel <?php if($az_data['most_viewed_play']) { echo 'auto-play'; } else {echo 'nauto-play';} ?>">
                <?php
               if($az_data['most_saled']) {
                $popularpost = new WP_Query( array(
                   'posts_per_page' => 8,
                   'post_type' => 'product',
                   'post_status' => 'publish',
                   'meta_key' => 'total_sales',
                   'orderby' => 'meta_value_num',
                   'order' => 'DESC'  ) );
                }
                else {
                $popularpost = new WP_Query( array(
                    'posts_per_page' => 8,
                    'post_type' => 'product',
                    'post_status' => 'publish',
                    'meta_key' => 'post_views_count',
                    'orderby' => 'meta_value_num',
                    'order' => 'DESC'  ) );
                }     
               if ( $popularpost->have_posts() ) {
               while ( $popularpost->have_posts() ) : $popularpost->the_post(); ?>
                <div class="item">
                    <div class="rcol">
                        <div class="r-box r-box-view">
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                <div class="figure">
                                    <div class="fig">
                                        <span class="fig-price">
                                            <span>
												<?php $product = new WC_Product(get_the_ID()); 
												echo $product->get_price_html(); ?></span>
											</span>
                                        <?php p_mimg() ?>
                                        <?php 
                   if(rwmb_meta( 'file_special' )){ ?>
                                        <span class="special" aria-hidden="true">
                                            <?php echo $az_data['text_special']; ?></span>
                                        <?php } ?>
                                    </div>
                                    <div class="figcaption">
                                        <?php the_title(); ?>
                                    </div>
                                </div>
                            </a>
                        </div>
                    </div>
                </div>
                <?php endwhile;
                   }
                else {echo 'فایلی با شرایط مورد نظر یافت نشد.';}
                     wp_reset_postdata();
                     ?>
            </div>
        </div>
    </div>