<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
global $post;
global $product;
$catname = wp_get_post_terms( $product->get_id(), 'product_cat', array());
$catlink = get_term_link( $catname[0]->term_id , 'product_cat' );
$brname = wp_get_post_terms( $product->get_id(), 'brands', array());
if ( isset( $brname[0] ) ) {
    $brlink = get_term_link( $brname[0]->term_id , 'brands' );
}
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();
$sale_price = $product->get_sale_price();
$normal_price = $product->get_regular_price();
$pr_id = get_the_ID();
$sold_individually = get_post_meta( $product->get_id(), '_sold_individually', true );

?>

<div class="d-flex align-items-center justify-content-between">
              <div class="count-comment-rate position-relative">
                <span>
                  <b> <?php echo $review_count; ?> </b>
                  نظر
                </span>
                <span>
                  <i class="icon-star"></i>
                  <?php echo $average; ?>
                </span>
              </div>
              <ul class="icons d-flex align-items-center">
                <li>
                  <a href="#">
                    <?php
              if ( is_plugin_active( 'woo-smart-compare/wpc-smart-compare.php' ) ) {
                echo do_shortcode( '[woosc id="".<?php echo get_the_ID(); ?>.""]' ); 
              } else {
                  
              }
              ?>
                  </a>
                </li>
                <li>
                  <a href="#">
                    <i class="isax isax-share5" data-bs-toggle="modal" data-bs-target="#exampleModal"></i>
                  </a>
                </li>
                <li>
                  <a href="#">
                            <?php
      if ( is_plugin_active( 'woo-smart-wishlist/wpc-smart-wishlist.php' ) ) { ?>
        <?php echo do_shortcode( '[woosw id="".<?php echo get_the_ID(); ?>.""]' ); ?>
      <?php
      } else {
          
      }
      ?>
                  </a>
                </li>
              </ul>


            </div>
            <?php
            if ($date_from = get_post_meta($pr_id, '_sale_price_dates_from', true)){
                $sale_price_dates_from = date('Y-m-d 00:00:00', $date_from);
            }
            if ($date_to = get_post_meta($pr_id, '_sale_price_dates_to', true)){
                $sale_price_dates_to = date('Y-m-d 23:59:59', $date_to);
            }
            if(!empty($sale_price_dates_from)):
            $deal_start_date = $sale_price_dates_from;
            $deal_start_time = strtotime($deal_start_date);
            $deal_end_date = $sale_price_dates_to;
            $deal_end_time = strtotime($deal_end_date, current_time('timestamp'));
            //$current_date = current_time( 'Y-m-d H:i:s', true );
            $current_time = strtotime('NOW', current_time('timestamp'));
            $time_diff = ($deal_end_time - $current_time); 
            endif;
            ?>
            <?php if (!empty($deal_end_date)): ?>
            <div class="timear d-flex align-items-center justify-content-between">
            <div class="title">
                پیشنهاد شگفت انگیز
                <span> فرصت باقی مانده </span>
            </div>
            
            <ul class="d-flex align-items-center" data-time="<?php  echo $deal_end_date; ?>">
                <li>
                <span class="second"> 00 </span>
                ثانیه
                </li>
                <li>
                <span class="minute"> 00 </span>
                دقیقه
                </li>
                <li>
                <span class="hour"> 00 </span>
                ساعت
                </li>
                <li>
                <span class="day"> 00 </span>
                روز
                </li>
            </ul>
            </div>
            <?php endif; ?>
            <ul class="info-product d-flex align-items-center flex-wrap">
            <?php if(!empty($catname[0]->name)): ?>
              <li>
                <span> دسته بندی </span>
                <a href="<?php echo $catlink; ?>"> <?php echo $catname[0]->name; ?> </a>
              </li>
              <?php endif; ?>
              <?php
                $cus_l = get_post_meta( get_the_ID(), "cus_lab_g", true );
                $cus_v = get_post_meta( get_the_ID(), "cus_lab_g", true );
                if(!empty($cus_l) and !empty($cus_v)):
                ?>
              <li>
                <span> <?php echo $cus_l[0]['cus_lab']; ?> </span>
                <span> <?php echo $cus_v[0]['cus_val']; ?> </span>
              </li>
              <?php
                endif;
                ?>
                <?php if(!empty($brname[0]->name)): ?>
              <li>
                <span> برند </span>
                <a href="<?php echo $brlink; ?>"> <?php echo $brname[0]->name; ?> </a>
              </li>
              <?php
                endif;
                ?>
            </ul>
            <br>
           
            <div class="price-add-to-cart">
                <?php if ( !$product->is_type( 'variable' ) ) : ?>
                    <?php if(!empty($sale_price) ): ?>
                    <div class="offer-product">
                        <span> <?php
                $percentage = round( ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100 );
                echo $percentage . "%";
                ?> </span>
                        تخفیف
                    </div>
                    <?php endif; ?>
                    <div class="mt-4"></div>
               <div class="price d-flex align-items-center mt-3 mb-4 mt-sm-0">
                <?php
                $price_v = $product->get_price_html(); 
                echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v);
                ?>
                </div>
                <div class="mt-4"></div>

                <?php
				      woocommerce_template_single_add_to_cart();
                ?>
              <?php elseif ( $product->is_type( 'variable' ) ) : 
              ?>
                <?php
				      woocommerce_template_single_add_to_cart();
                ?>
                <div class="mt-4"></div>
               <div class="price d-flex align-items-center mt-3 mb-4 mt-sm-0">
                <?php
                $price_v = $product->get_price_html(); 
                echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v);
                ?>
                </div>

              <?php
              endif; ?>
             
            </div>
           

          