<?php
/**

 * @see 	    https://docs.woocommerce.com/document/template-structure/
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     1.6.4
 */

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

global $product;

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


<div id="popup-wrapper1" class="modal modalvideo">

  <!-- Modal content -->
  <div class="modal-content">
    <a href="#modal-close" class="modal-close" onClick="PopUp1('hide1')">X</a>   	

<div class="video-sepid-p-single">
<video id="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>


		<?php } ?>		
<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="http://www.facebook.com/sharer.php?u=<?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>
				
				
<!-- end sc-amazing-offer -->
 	<?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 $option_meta = rwmb_meta('videol'); if (!empty($option_meta)) { ?>
<script>
    function PopUp1(hideOrshow) {
  if (hideOrshow == 'hide1') {
    document.getElementById('popup-wrapper1').style.display = "none";
    document.getElementById('video').pause(); // add this
  }
  else {
    document.getElementById('popup-wrapper1').removeAttribute('style');
        document.getElementById('popup-wrapper1').style.display = "block";

  }
}
</script><?php } ?>


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


<div class="mizan">
	<?php echo apply_filters( 'woocommerce_sale_flashtwo', $product ); ?>


</div>
	<?php
endif;

?>
 	<?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"> 
<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"> 

   
<div class="side-meta-1-box jjjok" id="shareb">
<i class="mdi mdi-share-variant"></i>
<h5>اشتراک</h5>

</div></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 class="side-meta-1-box-2"> 

<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>
<h5>اصالت کالا</h5>
</div></div>
<div class="side-meta-1-box-2"> 

<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>
<div class="side-2">
<div class="onvan-11">
<h1 class="title-1">
<?php the_title(); ?>
</h1>
  <?php $option_meta = rwmb_meta('title-1'); if (!empty($option_meta)) { ?>
<p>  <?php echo $option_meta; ?></p>

<?php } ?>
<div class="koli234234">


<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>

</div>

<div class="yekyek">


<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>
<?php $option_meta = rwmb_meta('wysiwyg_1'); if (!empty($option_meta)) { ?>


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

</div>
<?php } ?>




<?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 if((get_option('farnamone') == true )): ?>
<span class="rasmi1"><i class="mdi mdi-shield-check"></i>   <?php global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
echo ''. sprintf( __( '%s', 'woocommerce' ), $units_sold ).''; ?>   فروش موفق برای این محصول</span>
<?php endif; ?>

<?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 class="product-meta-mini">
<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></div>
<div class="dodo">



<?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;
		
		
				
		
								
				
	
		
            echo '<div class="iran-pak in-offer-2 nevise"><div id="fm" 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")
  .countdown("'; print_r($date); echo '", function(event) {
   $(".days").html(event.strftime("%D"));
   $(".hours").html(event.strftime("%H"));
   $(".minutes").html(event.strftime("%M"));
   $(".seconds").html(event.strftime("%S"));
});
</script></div>
';
}
          			

   


								}
								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;



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




<div id="ffggrr" 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">
  $("#ffggrr")
.countdown("'; print_r($date); echo '", function(event) {
   $(".days").html(event.strftime("%D"));
   $(".hours").html(event.strftime("%H"));
   $(".minutes").html(event.strftime("%M"));
   $(".seconds").html(event.strftime("%S"));
});
</script>


</div>					
									
									
';
								}}
								

  
?>





					

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


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

<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>

<?php endif; ?>

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

 <?php endwhile; endif; ?>
 
 <?php 
?>


 <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 )): ?>
			 <script>
   $(document).ready(function(){
$('.owl-offer11').owlCarousel({
    loop:true,
     autoplay:true,
    autoplayTimeout:7000,
    autoplayHoverPause:true,
    rtl: true,
    nav:true,
	dots:true,
        margin:10,
    dots: false,
    responsive:{
        0:{
            items:1
        },
        360:{
            items:2,
			        margin:0

			
        },
		900:{
            items:3
        },
        1200:{
            items:4
        }
    }
})
});
</script>
 <div class="main-asl-product owl-pone12">
 <div class="size ns-402-22">
 <h2 class="title-2">محصولات مرتبط</h2>
    <div class="owl-offer11 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(); ?>
 <div class="ps1-1">

 <div class="product-list-1 ps1">
<?php if ( $product->is_on_sale() ) : ?>


<div class="mizan">
	<?php echo apply_filters( 'woocommerce_sale_flashtwo', $post, $product ); ?>


</div>
	<?php
endif;
?>
<a href="<?php the_permalink(); ?>">
	<?php the_post_thumbnail('woocommerce_thumbnail'); ?><h3><?php the_title(); ?></h3>
</a>
<div class="rangbandi-style-1400">

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

<?php
    
    
$values = rwmb_meta("colorin1");
//print_r($values);
//if(!empty($values)){
    //print_r($values);
foreach ( $values as $value ) {
                    echo '<div class="rangi-dayere-342" style="background: ';
print_r( $value );	   
	
                    echo ';"></div>';

}
//}
?><?php } ?>
</div>
<div class="list-meta">

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

<span class="list-meta-1">

 <?php global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
echo ''. sprintf( __( '%s', 'woocommerce' ), $units_sold ).''; ?> 
</br>
 فروش </span><?php endif; ?>

<span class="list-meta-2">
<?php global $product; echo $product->get_price_html(); ?>
 <?php
				do_action( 'woocommerce_namojood' );
	?>
	
</span>
</div>
<div class="risk-meta">
<div class="liningk bazsho1">
<div class="tooltiping">
علاقه مندی به محصول</div>
<?php echo do_shortcode("[yith_wcwl_add_to_wishlist]"); ?>
</div>
<span class="cpmare-wefew bazsho1">
<div class="tooltiping">
مقایسه این محصول</div>
<?php echo do_shortcode( '[woosc id=' . get_the_ID() . ']' ); ?>
</span>

<span class="cpmare-wefew-1 bazsho1">
<div class="tooltiping">
مشاهده سریع محصول</div>
<?php echo do_shortcode( '[woosq id=' . get_the_ID() . ']' ); ?>
</span>
<a href="<?php the_permalink(); ?>">
<span class="rangi-1">
<i class="mdi mdi-basket"></i>
</span></a>

</div>
</div></div>
<?php endwhile; endif; wp_reset_postdata(); ?>
 </div>
 </div>
 </div>

<?php endif; ?>


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

<?php get_footer();

