<?php
/**
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 1.6.4
 */
 
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $product;

get_header(); ?>

<div id="videom" class="modalz">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close3">&times;</span>
<div class="video-sepid-p-single">
<video controls="" poster="<?php $option_meta = rwmb_meta('videot'); if (!empty($option_meta)) { ?><?php echo $option_meta; ?><?php } ?>">
                        <source src="<?php $option_meta = rwmb_meta('videol'); if (!empty($option_meta)) { ?><?php echo $option_meta; ?><?php } ?>" type="video/mp4">
                    </video>
</div>

  </div>

</div>
<div id="sharem" class="modal1">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close1">&times;</span>
	<div class="sgare-sepid-box">

	<h4> 	<div class="product-aspk">
	
	 <?php the_post_thumbnail('thumbnail'); ?>
	 
	 
	 </div><div class="chap-12221"><i class=" fi fi-rr-share"></i> اشتراک گذاری </div> <span><?php the_title(); ?></span></h4>
	<div class="share-3">
<a class="twi" target="_blank" href="https://twitter.com/home?status=<?php the_permalink(); ?>"><i class="mdi mdi-twitter"></i></a>
<a class="link" target="_blank" href="https://www.linkedin.com/shareArticle?mini=true&amp;url==<?php the_permalink(); ?>"><i class="mdi mdi-linkedin"></i></a>

<a class="tel" target="_blank" href="https://telegram.me/share/url?url=<?php the_permalink(); ?>"><i class="mdi mdi-telegram"></i></a>
<a class="whstaspp" target="_blank" href="https://api.whatsapp.com/send?text=<?php the_permalink(); ?>"       data-action="share/whatsapp/share"  
        target="_blank"><i class="mdi mdi-whatsapp"></i></a>
<a class="face" target="_blank" href="https://www.facebook.com/sharer/sharer.php?m2w&s=100&p[url]=<?php the_permalink(); ?>"><i class="mdi mdi-facebook"></i></a>



</div>
<script>
function myFunction() {
  /* Get the text field */
  var copyText = document.getElementById("myInput");

  /* Select the text field */
  copyText.select();
  copyText.setSelectionRange(0, 99999); /* For mobile devices */

   /* Copy the text inside the text field */
  navigator.clipboard.writeText(copyText.value);

  /* Alert the copied text */
} 
</script>

<div class="link-kootah">
<button onclick="myFunction()"><i class="fi fi-rr-copy"></i></button>


<input id="myInput" value="<?php bloginfo('url'); ?>/?p=<?php the_ID(); ?>">
</div>
	</div>
</div>

  </div>
			
 	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="product-bread">
<div class="size">
<div class="product-bread-1">

 <?php woocommerce_breadcrumb(); ?>

</div>
</div>
</div>
<div class="msdfsd-23423">
<div class="size">
 <?php
				do_action( 'woocommerce_before_single_product' );
	?>
	
	</div>	
	</div>
		<div class="product type-product">

<div class="main-asl-product">
<div class="size">
<div class="main-asl-product-1">
<div class="side-1">
<div class="img-side1">

<div class="img-side">


 	<?php do_action( 'woocommerce_before_single_product_summary' ); ?>

</div></div>

		     <?php if((get_option('farnamfour') == true )): ?>

<div class="side-meta-1">
<div class="side-meta-1-box-2 vase-demo-2 share-new-demo tooltipdemo2">
<div class="tooltip-demo-2">
علاقه مندی ها</div>
<div class="side-meta-1-box ksfgfdg">
<?php echo do_shortcode( '[yith_wcwl_add_to_wishlist product_id=' . get_the_ID() . ']' ); ?>

</div></div>
<div class="side-meta-1-box-2 vase-demo-2"> 

 
<div class="side-meta-1-box jjjok share-new-demo tooltipdemo2" id="shareb" >
<div class="tooltip-demo-2">
اشتراک گذاری
</div>
<i class="mdi mdi-share-variant"></i>


</div>
<script>
// Get the modal
var modal1 = document.getElementById("sharem");

// Get the button that opens the modal
var btn = document.getElementById("shareb");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close1")[0];

// When the user clicks on the button, open the modal
btn.onclick = function() {
  modal1.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modal1.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modal1) {
    modal1.style.display = "none";
  }
}
</script>

</div>
<?php $option_meta = rwmb_meta('videol'); if (!empty($option_meta)) { ?>
<div class="side-meta-1-box-2 vase-demo-2 vd3401"> 

 
<div class="side-meta-1-box jjjok share-new-demo tooltipdemo2" id="videob" >
<div class="tooltip-demo-2">
ویدیو معرفی محصول
</div>
<i class="fi fi-rr-play"></i>


</div>
<script>


// Get the modal
var modalz = document.getElementById("videom");

// Get the button that opens the modal
var btn = document.getElementById("videob");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close3")[0];

// When the user clicks on the button, open the modal
btn.onclick = function() {
  modalz.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  modalz.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
  if (event.target == modalz) {
    modalz.style.display = "none";
  }
}

</script>

</div>
<?php } ?>
<div class="side-meta-1-box-2 vase-demo-2 share-new-demo tooltipdemo2">
<div class="tooltip-demo-2">
محصول اورجینال است</div>

<div class="side-meta-1-box  <?php $option_meta = rwmb_meta('asl'); if (!empty($option_meta)) { ?>
<?php echo $option_meta; ?>
<?php } ?>">
<i class="mdi mdi-checkbox-marked-circle-outline"></i>
</div></div>
<div class="side-meta-1-box-2 vase-demo-2 share-new-demo tooltipdemo2">
<div class="tooltip-demo-2">
مقایسه محصول</div>

<div class="side-meta-1-box ghgfhtr">
<?php echo do_shortcode( '[woosc id=' . get_the_ID() . ']' ); ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="bars-prog">
										<?php farnam_stock_progress_bar(); ?>
</div>
<div class="roozbehtar-hddd"><?php $option_meta = rwmb_meta('had'); if (!empty($option_meta)) { ?>
<div class="box-rasmi-meta">
<div class="meta-rasmi-1"><div class="meta-rasmi-2">  <i class="mdi mdi-timer-sand"></i>حداکثر تا  
<?php echo $option_meta; ?> 
روز تحویل داده میشود</div></div>
</div><?php } ?> 
<div class="rasmi">
<?php $option_meta = rwmb_meta('zemanat'); if (!empty($option_meta)) { ?><span class="rasmi2"><i class="mdi mdi-car-pickup"></i>  
<?php echo $option_meta; ?>
</span><?php } ?>

</div></div>
</div>
<div class="side-2">
<div class="onvan-11">
<div class="new-title-2020">
<h1 class="title-1">
<?php the_title(); ?>
</h1>

<?php global $product; if ( $product->is_on_sale() ) : ?>




<span>
	<?php echo apply_filters( 'woocommerce_sale_flashtwo', $post, $product ); ?>  تخفیف
</span>
	<?php
endif;
?>

</div>
  <?php $option_meta = rwmb_meta('title-1'); if (!empty($option_meta)) { ?>
<p><?php echo $option_meta; ?></p>

<?php } ?>

<div class="jodanasho"><div class="jodasho">
<div class="jodasho-iran">

</div>
</div></div>

<div class="class-star">

    <?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $product;

if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
	return;
}

$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();

if ( $rating_count > 0 ) : ?>

	<div class="woocommerce-product-rating">
		<?php echo wc_get_rating_html( $average, $rating_count ); ?>
		<?php if ( comments_open() ) : ?><?php endif ?>
		     <?php if((get_option('farnamfour3') == true )): ?>

		<a href="#emtiazha" class="emtiazx">جزییات امتیاز ها</a><?php endif; ?>
	</div>

<?php endif; ?>
</div>
</div>
		     <?php if((get_option('farnamone') == true )): ?>

<div class="tedadforoosh">
<i class="mdi mdi-trophy-outline"></i>
<span><?php global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
echo ''. sprintf( __( '%s', 'woocommerce' ), $units_sold ).''; ?> فروش موفق</span>
</div><?php endif; ?>
<div class="yekyek">

<div class="hamrasta">
<div class="adfdf4544"> <?php $option_meta = rwmb_meta('catalog'); if (!empty($option_meta)) { ?>

<a href="<?php echo $option_meta; ?>" target="_blank" class="meta-catalog-date-box ert45t55">
<i class="fi fi-rr-download"></i>
دانلود کاتالوگ

</a><?php } ?>


		     <?php if((get_option('farnamthree31') == true )): ?>

<div  class="meta-catalog-date-box">
<i class="fi fi-rr-calendar"></i>
آخرین بروزرسانی :                         <?php the_modified_time('Y/m/d'); ?>

</div><?php endif; ?></div>
<div class="product-meta-mini kknews-stark">
<div class="product-meta-mini-1">
	<i class="mdi mdi-menu"></i>
	
	
	<?php echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count( $product->get_category_ids() ), 'woocommerce' ) . ' ', '</span>' ); ?>

</div>
<?php
$product_id = get_the_ID();

$brands = wp_get_post_terms($product_id, 'product_brand');

if (!empty($brands) && !is_wp_error($brands)) {
    $brand_name = $brands[0]->name;
} else {
    $brand_name = '';
}

if (!empty($brand_name)) { ?>
    <div class="product-meta-mini-1">
        <i class="mdi mdi-copyright"></i>
        برند : <span class="span98"><?php echo esc_html($brand_name); ?></span>
    </div>
<?php }

else { ?>
 <?php $option_meta = rwmb_meta('brand'); if (!empty($option_meta)) { ?>
<div class="product-meta-mini-1">
	<i class="mdi mdi-copyright"></i>
برند : <span class="span98"><?php echo $option_meta; ?></span></div>
<?php }} ?>
<?php echo wc_get_product_tag_list( $id = $product->get_id(), ', ', '<div class="product-meta-mini-1">
	<i class="mdi mdi-tag"></i>' . _n( 'Tag:', 'Tags:', count( $product->get_tag_ids() ), 'woocommerce' ) . ' ', '</div>' ); ?>

</div>

<?php $option_meta = rwmb_meta('wysiwyg_1'); if (!empty($option_meta)) { ?>

<div class="vijegi">
<?php echo $option_meta; ?>

</div>
<?php } ?>



 <div class="price-kharid-new">
 <?php
			do_action( 'woocommerce_single_product_summary' );
		?>
 </div>
 
</div>

<div class="etel-111 demo-tw0-etel">


<div class="ning-stark">

           <?php 
		   
		   
		   
		   
		   global $post;
								if(  $product->is_on_sale() && $product->is_type('variable')){
					

	

							
		 
    if( $product->is_type('variable') ){
        $default_attributes = $product->get_default_attributes();
        foreach($product->get_available_variations() as $variation_values ){
            foreach($variation_values['attributes'] as $key => $attribute_value ){
                $attribute_name = str_replace( 'attribute_', '', $key );
                $default_value = $product->get_variation_default_attribute($attribute_name);
                if( $default_value == $attribute_value ){
                    $is_default_variation = true;
                } else {
                    $is_default_variation = false;
                    break; // Stop this loop to start next main lopp
                }
            }
            if( $is_default_variation ){
                $variation_id = $variation_values['variation_id'];
                break; // Stop the main loop
		
            }
        }

global $product;

if ($product->is_on_sale() && $product->is_type('variable') ) {
    $default_variation_id = 0;
    $default_variation = $product->get_available_variations()[0];
    if (is_a($default_variation, 'WC_Product_Variation')) {
        $variation_id = $default_variation->get_variation_id_by_sku($default_variation->get_sku());
    }
	
if ($product->is_on_sale() && $product->is_type('variable')) {
    global $product;

    $variation_id = null;

    if ($product->is_type('variable')) {
        $default_attributes = $product->get_default_attributes();
        foreach ($product->get_available_variations() as
 
$variation_values) {
            foreach ($variation_values['attributes'] as
 
$key => $attribute_value) {
                $attribute_name = str_replace('attribute_', '', $key);
                $default_value = $product->get_variation_default_attribute($attribute_name);

                if ($default_value == $attribute_value) {
                    $variation_id = $variation_values['variation_id'];
                    break 2; // Exit both loops
                }
            }
        }
    }

    if ($variation_id) {
        $sale_end_date = get_post_meta($variation_id, '_sale_price_dates_to', true);
    } else {
        // Variation is not selected, so don't display anything
    }
}
    if (empty($sale_end_date) || $sale_end_date < current_time('timestamp')) {
								        // چیزی نمایش داده نمیشود
    } else {
        // The discount is still active
 

        // Now we get the default variation data
        if( $is_default_variation ){
            // Raw output of available "default" variation details data
		 $meta_date = get_post_meta( $variation_id, '_sale_price_dates_to', true );
					if( empty( $meta_date ) ){
																//	echo esc_html_e( 'زمان بندی پیشنهاد ویژه تعیین نشده است!', 'studiare' );
															}
          	else{
					$date  = date( 'm/d/Y 23:59', $meta_date );//echo $date;
			
			
			?>

						

<div class="iran-pak in-offer-2 nevise">




<div id="fm<?php echo get_the_ID(); ?>" class="timer">

   <div class="timer-wrapper">
      <div class="days time1"></div><span class="text32">روز</span>
   </div>

   <div class="timer-wrapper">
      <div class="hours time1"></div> <span class="text32">ساعت</span>
   </div>

   <div class="timer-wrapper">
      <div class="minutes time1"></div> <span class="text32">دقیقه</span>
   </div>

   <div class="timer-wrapper">
      <div class="seconds time1 mini-1-time"></div> <span class="text32">ثانیه</span>
   </div>

</div>


<script type="text/javascript">
  $("#fm<?php echo get_the_ID(); ?>")
  .countdown("<?php echo esc_attr( $date ) ?>", function(event) {
   $(".days").html(event.strftime('%D'));
   $(".hours").html(event.strftime('%H'));
   $(".minutes").html(event.strftime('%M'));
   $(".seconds").html(event.strftime('%S'));
});
</script>


</div>		<?php
          	}		

   


								}
								else {
								        // چیزی نمایش داده نمیشود
	
									
								}
			}
					   }
}			
									}
								
								else {
									
							



  $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
															if( empty( $meta_date ) ){
																//	echo esc_html_e( 'زمان بندی پیشنهاد ویژه تعیین نشده است!', '' );
															}
					else{
					// $date  = date_i18n( 'm/d/Y', $meta_date );
					}
					
					
					
 $sale_end_date = get_post_meta($product->get_id(), '_sale_price_dates_to', true);
  if ($sale_end_date < current_time('timestamp')) {
    // تخفیف به پایان رسیده است، بنابراین تایمر را نمایش ندهید
  } else {
	  global $post;


					$date  = date( 'm/d/Y 23:59', $sales_price_to );//echo $date;


?>



<div id="fm<?php echo get_the_ID(); ?>" class="timer">

   <div class="timer-wrapper">
      <div class="days time1"></div><span class="text32">روز</span>
   </div>

   <div class="timer-wrapper">
      <div class="hours time1"></div> <span class="text32">ساعت</span>
   </div>

   <div class="timer-wrapper">
      <div class="minutes time1"></div> <span class="text32">دقیقه</span>
   </div>

   <div class="timer-wrapper">
      <div class="seconds time1 mini-1-time"></div> <span class="text32">ثانیه</span>
   </div>

</div>
<script type="text/javascript">
  $("#fm<?php echo get_the_ID(); ?>")
  .countdown("<?php echo esc_attr( $date ) ?>", function(event) {
   $(".days").html(event.strftime('%D'));
   $(".hours").html(event.strftime('%H'));
   $(".minutes").html(event.strftime('%M'));
   $(".seconds").html(event.strftime('%S'));
});
</script>
<?php
								}}
								

  
?>


					
		     <?php if((get_option('farnamtwo') == true )): ?>

<div class="meta-demo-3-s">
<div class="etel-111">
<div class="etel-111-1">
<img src="<?php echo get_option('imgslide1'); ?>
">
<div class="mizan-6"><?php echo get_option('tedad'); ?></div>
<h4><?php echo get_option('linkslide1'); ?></h4>
</div><div class="etel-111-1">
<img src="<?php echo get_option('imgslide2'); ?>
">
<h4><?php echo get_option('linkslide2'); ?></h4>
</div><div class="etel-111-1">
<img src="<?php echo get_option('imgslide3'); ?>
">
<h4><?php echo get_option('linkslide3'); ?></h4>

</div><div class="etel-111-1">
<img src="<?php echo get_option('imgslide4'); ?>
">
<h4><?php echo get_option('linkslide4'); ?></h4>
</div><div class="etel-111-1">
<img src="<?php echo get_option('imgslide5'); ?>
">
<h4><?php echo get_option('linkslide5'); ?></h4>
</div>


</div>
</div>
<?php endif; ?>
</div>
</div></div>





</div></div>
</div>
</div>
 <?php endwhile; endif; ?>
 <div class="main-asl-product">
<div class="size">
<div class="main-asl-product-1">
  			<?php wc_get_template_part( 'content', 'single-product' ); ?>
</div></div></div>


		     <?php if((get_option('farnamfour3') == true )): ?>


 <div id="emtiazha" class="main-asl-product" style="margin-top: 0px;">
<div class="size">                <div class="main-asl-product-1">
<h2 class="title-2" style="margin-top: 0px;margin-bottom: 35px;padding: 0px 0px;box-sizing: border-box;font-size: 18px;font-weight: 400;">امتیاز دریافتی محصول از کاربران</h2>                       <div class="emtiaz-2">
                            <!-- Averate Rating -->
                            <div class="emtiaz-3">
						
							                            <div class="emtiaz-33">
	<div class="emtiaz-title">
							متوسط امتیاز ها
							</div>
                                    <div class="emtiaz-number"><?php echo esc_attr($average); ?></div>
                              <div class="emtiaz-star">
							                                          <?php do_action( 'woocommerce_after_shop_loop_item_title' ); ?>

							  </div>
                                   
                            </div></div>

                            <!-- Detailed Ratings-->
                            <?php
                            // WP_Comment_Query arguments
                            $args = array (
                                'status'         => 'approve',
                                'type'           => 'review',
                                'post_id'        => get_the_id(),
                            );

                            // The Comment Query
                            $woo_reviews = new WP_Comment_Query;
                            $comments = $woo_reviews->query( $args );

                            $rate1 = $rate2 = $rate3 = $rate4 = $rate5 = 0;
                            // The Comment Loop
                            if ( $comments ) {
                                foreach ( $comments as $comment ) {
                                    $rate = get_comment_meta($comment->comment_ID, 'rating', true);
                                    switch($rate) {
                                        case 1:
                                            $rate1++;
                                            break;
                                        case 2:
                                            $rate2++;
                                            break;
                                        case 3:
                                            $rate3++;
                                            break;
                                        case 4:
                                            $rate4++;
                                            break;
                                        case 5:
                                            $rate5++;
                                            break;
                                    } // switch
                                }
                            }
                            $rates = array('5'=>$rate5,'4'=>$rate4,'3'=>$rate3,'2'=>$rate2,'1'=>$rate1);
                            ?>
                            <div class="emtiaz-4">
						
                                <div class="emtiaz-5">
	                                <?php foreach($rates as $key => $rate): ?>
		                                <?php
		                                if($rate !=0 or $rating_count != 0) {
			                                $fill_value = round($rate*100/$rating_count, 2);
		                                } else {
			                                $fill_value = 0;
		                                }
		                                ?>
                                        <div class="emtiaz-6">
										                                            <span class="number"><?php echo esc_attr($key.' '.__('ستاره', 'studiare')); ?></span>

                                            <div class="bars">
                                                <div class="barsf" style="width:<?php echo esc_attr($fill_value); ?>%"></div>
                                            </div>
                                            <span class="shomaresh"><?php echo esc_attr($rate); ?></span>
                                        </div>
	                                <?php endforeach; ?>
                                </div>
                            </div>
                        </div>

            
                </div>	

</div>
</div>
<?php endif; ?>

		     <?php if((get_option('farnamthree') == true )): ?>

 <div class="main-asl-product owl-pone12 nasle1">
 <div class="size">
 <h2 class="title-2">محصولات مرتبط</h2>
    <div class="owl-ponett1 owl-carousel">
	<?php $cats_array=array(0); $terms=wp_get_post_terms($product->get_id(),'product_cat');
	foreach($terms as $term){$children=get_term_children($term->term_id,'product_cat');
	if(!sizeof($children)) $cats_array[]=$term->term_id;}
	$args=apply_filters('woocommerce_related_products_args',
	array('post_type'=>'product','ignore_sticky_posts'=>1,'no_found_rows'=>1,
	'posts_per_page'=>8,'orderby'=>'rand',
	'meta_query'=>array(array('key'=>'_stock_status','value'=>'instock')),
	'tax_query'=>array(array('taxonomy'=>'product_cat','field'=>'id','terms'=>$cats_array),)));
	$related_items=new WP_Query($args);
	if($related_items->have_posts()):while($related_items->have_posts()):$related_items->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="product-demo-2-1-3">

<div class="product-demo-2-1">
<div class="product-demo-2-1-2">
<div class="product-demo-2-img">

<?php the_post_thumbnail('woocommerce_thumbnail'); ?>
</div>
<div class="product-demo-2-listing">
<h3><?php the_title(); ?></h3>
<div class="home-star woocommerce">

<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $product;

if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) {
	return;
}

$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();

if ( $rating_count > 0 ) : ?>

	<div class="woocommerce-product-rating">
		<?php echo wc_get_rating_html( $average, $rating_count ); ?>
		<?php if ( comments_open() ) : ?><?php endif ?>
	</div>

<?php endif; ?></div>
<div class="product-demo-2-listing1"></div>
<div class="mini-price-demo-1"><?php  global $product; echo $product->get_price_html(); ?></div>
</div>
</div>
</div></a>
<?php endwhile; endif; wp_reset_postdata(); ?>
 </div>
 </div>
 </div> 
<?php endif; ?>
</div>
 </div>

<?php get_footer();

