<?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();
$min_regular_price = NULL;
$max_regular_price = NULL;
$min_sale_price = NULL;
$max_sale_price = NULL;
if ($product->is_type('variable')) {
  $min_regular_price = $product->get_variation_regular_price('min');
  $max_regular_price = $product->get_variation_regular_price('max');
  $min_sale_price = $product->get_variation_sale_price('min');
  $max_sale_price = $product->get_variation_sale_price('max');
}
$pr_id = get_the_ID();
$stocka = $product->get_stock_status();
?>
<div <?php wc_product_class('product-seven', $product); ?>>
    <h2 class="product-name">
        <a href="<?php the_permalink(); ?>"> <?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>
    </h2>
    <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();
if ( wp_is_mobile() ) {
    echo wp_trim_words( $title, 5, '...' );
} else {
    echo wp_trim_words( $title, 8, '...' );
}
?>" />
        </a>
    </div>
    <?php if ("instock" == $stocka) { ?>
        <?php if (!$product->is_type('variable')) { ?>
            <?php if (empty($sale_price) && empty($normal_price)) { ?>
                <?php
                $price_v = $product->get_price_html(); ?>
                <div><?php
                echo str_replace("&ndash;", "<span class=\"dashvar\"> – </span>", $price_v); ?>
                </div>
                <?php
                ?>
            <?php } else { ?>
                <?php if (!empty($sale_price)) { ?>
                    <div class="price">
                        <del> <?php if (!empty($normal_price)) {
                            echo number_format($normal_price, 0, '.', ',');
                        } ?> </del>
                        <span> <?php echo number_format($sale_price, 0, '.', ','); ?> </span>
                        <?php echo $woo_currency; ?>
                    </div>
                <?php } else { ?>
                    <div class="price">
                        <span> <?php if (!empty($normal_price)) {
                            echo number_format($normal_price, 0, '.', ',');
                        } ?> </span>
                        <?php echo $woo_currency; ?>
                    </div>
                <?php } ?>
            <?php }
        } else { ?>
           

                <?php if ($product->is_on_sale()){ ?>
                    <div class="price">
                        <del> <?php if (!empty($max_regular_price)) {
                            echo number_format($max_regular_price, 0, '.', ',');
                        } ?> </del>
                        <span> <?php echo number_format($min_sale_price, 0, '.', ','); ?> </span>
                        <?php echo $woo_currency; ?>
                    </div>
                <?php } else { ?>
                    <div class="price">
                        <span>
                            <!-- show range -->
                            <?php if ($min_regular_price !== $max_regular_price): ?>
                                <?php if (!empty($min_regular_price)): ?>
                                    <?php echo number_format($min_regular_price, 0, '.', ',') . ' - ' . number_format($max_regular_price, 0, '.', ',') . ' '; ?>
                                <?php endif; ?>
                            <?php else: ?>
                                <?php if (!empty($min_regular_price)): ?>
                                    <?php echo number_format($min_regular_price, 0, '.', ',') . ' '; ?>
                                <?php endif; ?>
                            <?php endif; ?>
                            <!-- show range -->
                        </span>
                        <?php echo $woo_currency; ?>
                    </div>
                <?php } ?>

            <?php
        }
    }
    ?>
    <div class="d-flex align-items-center justify-content-between">
        <?php if ("instock" == $stocka) { ?>
            <?php if (!empty($normal_price)) { ?>
                <?php if (!$product->is_type('variable')) { ?>
                    <a href="<?php the_permalink(); ?>"
                        class="position-absolute bottom-0 start-0 ms-3 ms-md-3 ms-lg-3 ms-xl-3 ms-xxl-4 mb-3 btn btn-success-2 shadow-none">
                        + <?php esc_html_e('Buy', 'kavehTheme'); ?> </a>
                <?php } else { ?>
                    <a href="<?php the_permalink(); ?>"
                        class="position-absolute bottom-0 start-0 ms-3 ms-md-3 ms-lg-3 ms-xl-3 ms-xxl-4 mb-3 btn btn-success-2 shadow-none">
                        <?php esc_html_e('View Options', 'kavehTheme'); ?> </a>
                <?php }
            }
        } else { ?>
            <div class="price w-100 na6">
                <h6 class="mx-auto my-1 nam-6"><?php esc_html_e('Out of Stock', 'kavehTheme'); ?></h6>
            </div>
        <?php } ?>
        <?php if ($product->is_on_sale()): ?>
            <span class="position-absolute bottom-0 end-0 me-3 me-md-3 me-lg-3 me-xl-3 me-xxl-4 mb-3 offer">
                <?php if (class_exists('kavehWoo')) {
                    $offer_percentage = kavehWoo::showofferpercentage($product);
                    echo $offer_percentage;
                } ?>
            </span>
        <?php endif; ?>
    </div>
    <a href="<?php the_permalink(); ?>" class="btn btn-danger-2"> <?php esc_html_e('View and Review Product', 'kavehTheme'); ?> </a>
</div>