<?php
$product = wc_get_product(get_the_ID());
$sale_price = $product->get_sale_price();
$normal_price = $product->get_regular_price();
$options = kaveh_get_options();
$woo_currency = get_woocommerce_currency_symbol();
$pr_id = get_the_ID();
$stocka = $product->get_stock_status();
?>
<div <?php wc_product_class('product-eight', $product); ?>>
  <div class="image">
                <?php if($options['kaveh_compare_system'] === '1'): ?>   

    <?php echo do_shortcode('[compare_button id='. get_the_ID() .' style="icon_text" radius="50" tag="a" class="kaveh_compare_top"]'); ?>
                          <?php endif; ?>

    <a href="<?php the_permalink(); ?>">
      <img src="<?php if(get_the_post_thumbnail_url()): ?>
<?php the_post_thumbnail_url('full'); ?>
<?php else: ?>
<?php echo wc_placeholder_img_src(); ?>
<?php endif; ?>" alt="<?php
$title = get_the_title();
$show_full_titles = kaveh_get_option('kaveh_product_title_display', false);
if ($show_full_titles) {
    echo esc_html($title);
} else {
    if ( wp_is_mobile() ) {
        echo wp_trim_words( $title, 5, '...' );
    } else {
        echo wp_trim_words( $title, 8, '...' );
    }
}
?>" />
    </a>
    <?php if ($product->is_on_sale()): ?>
      <div class="offer">
        <?php if (class_exists('kavehWoo')) {
          $offer_percentage = kavehWoo::showofferpercentage($product);
          echo $offer_percentage;
        } ?>
      </div>
    <?php endif; ?>
  </div>
  <div class="content">
    <h2 class="product-name">
      <a href="<?php the_permalink(); ?>"> <?php
$title = get_the_title();
if ( wp_is_mobile() ) {
    echo wp_trim_words( $title, 5, '...' );
} else {
    echo wp_trim_words( $title, 8, '...' );
}
?></a>
    </h2>
    <div class="d-flex align-items-center justify-content-start">
    <div class="price">
    <?php
        // Use WooCommerce's built-in price HTML output
        $price_html = $product->get_price_html();
        // If we have price HTML (not empty)
        if ($price_html) {
            echo $price_html;
        }
        ?>
    </div>
        <?php

      if ("instock" == $stocka) { ?>
        <?php if (!$product->is_type('variable')) { ?>
          <a type="submit" name="add-to-cart" value="<?php echo $pr_id ?>"
            class="btn btn-success-2 shadow-none single_add_to_cart_button"><span> + <?php esc_html_e('Buy', 'kavehTheme'); ?> </span></a>
        <?php } else { ?>
        <?php }
      } else { ?>
        <span class="btn btn-notstock rounded-pill"><?php esc_html_e('Out of Stock', 'kavehTheme'); ?></span>
      <?php } ?>
    </div>
    <a href="<?php the_permalink(); ?>" class="btn btn-secondary rounded-pill"><?php esc_html_e('View Product', 'kavehTheme'); ?></a>
  </div>
</div>