<?php $kproduct = get_query_var('kproduct'); ?>
<?php $woo_currency = get_woocommerce_currency_symbol(); ?>
<?php
global $product;
$product = wc_get_product( get_the_ID() );   
?>
<div class="product-fifteen position-relative d-flex align-items-sm-center bg-white flex-column flex-sm-row">
<?php if ( $kproduct['kaveh_custom']['is_on_sale'] === true ): ?>
<div class="discount d-flex align-items-center justify-content-center position-absolute top-0 start-0">
<?php if($kproduct['kaveh_custom']['product_type'] === 'variable'): ?>
    <?php echo (int)(( ( (float)$kproduct['kaveh_custom']['min_regular_price'] - (float)$kproduct['kaveh_custom']['min_sale_price'] ) / (float)$kproduct['kaveh_custom']['min_regular_price'] ) * 100); ?><?php echo ' '.'%'; ?>
<?php elseif($kproduct['kaveh_custom']['product_type'] === 'simple'): ?>
    <?php echo (int)(( ( (float)$kproduct['kaveh_custom']['normal_price'] - (float)$kproduct['kaveh_custom']['sale_price'] ) / (float)$kproduct['kaveh_custom']['normal_price'] ) * 100); ?><?php echo ' '.'%'; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="image-price position-relative">
<ul
class="btns position-absolute top-50 start-50 translate-middle mb-0 d-flex d-sm-block align-items-center justify-content-center">
<li>
<a href="#" name="add-to-cart" value="<?php echo $kproduct['id']; ?>" class="d-flex align-items-center justify-content-center single_add_to_cart_button" aria-label="cart">
<i class="icon-cart-4"></i>
</a>
</li>
<li>
<a href="#" class="d-flex align-items-center justify-content-center" aria-label="toggle">
<i class="icon-arrow-toggle"></i>
</a>
</li>
<li>
<a href="#" class="d-flex align-items-center justify-content-center" aria-label="view">
<i class="icon-eye-2"></i>
</a>
</li>
</ul>
<img src="<?php echo $kproduct['kaveh_custom']['thumbnail_url'] ?>" alt="product" width="178" height="103">
<div class="price position-relative text-center text-sm-start">
<?php if($kproduct['kaveh_custom']['product_stock_status'] !== 'outofstock'): ?>
<?php if($kproduct['kaveh_custom']['product_type'] !== 'variable'): ?>

<?php if ( $kproduct['kaveh_custom']['is_on_sale'] === true ): ?>
<del class="d-block">  <?php echo number_format($normal_price, 0, '.', ','); ?> </del>
<div
class="d-flex align-items-center justify-content-center justify-content-sm-start position-relative">
<span> <?php if(!empty($kproduct['kaveh_custom']['sale_price'])): ?>
    <?php echo number_format($kproduct['kaveh_custom']['sale_price'], 0, '.', ','); ?>
<?php endif; ?> </span>
<?php echo $woo_currency; ?>
</div>
<?php else: ?>
<div class="d-flex align-items-center justify-content-center justify-content-sm-start position-relative">
<span> <?php echo number_format($normal_price, 0, '.', ','); ?> </span>
<?php echo $woo_currency; ?>
</div>
<?php endif; ?>
<?php else: ?>
<div class="d-flex align-items-center justify-content-center justify-content-sm-start position-relative">
<span> 
<?php if($kproduct['kaveh_custom']['min_regular_price'] !== $kproduct['kaveh_custom']['max_regular_price']): ?>
    <?php if(!empty($kproduct['kaveh_custom']['min_regular_price'])): ?>
    <?php echo number_format($kproduct['kaveh_custom']['min_regular_price'], 0, '.', ',') . ' - ' . number_format($kproduct['kaveh_custom']['max_regular_price'], 0, '.', ',') . ' '; ?>
<?php endif; ?>
<?php else: ?>
    <?php if(!empty($kproduct['kaveh_custom']['min_regular_price'])): ?>
    <?php echo number_format($kproduct['kaveh_custom']['min_regular_price'], 0, '.', ',')  . ' '; ?>
<?php endif; ?>
<?php endif; ?>    
</span>
<?php echo $woo_currency; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<div class="info text-center text-sm-start mt-3 mt-sm-0">
<a href="<?php echo $kproduct['link'] ?>"><h2 class="title mb-1"> <?php echo $kproduct['title']['rendered']; ?> </h2></a>
<div class="title-en">  </div>
<?php
$product_attributes = array();

// Display weight and dimensions before attribute list.
$display_dimensions = apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() );

if ( $display_dimensions && $product->has_weight() ) {
$product_attributes['weight'] = array(
'label' => __( 'Weight', 'woocommerce' ),
'value' => wc_format_weight( $product->get_weight() ),
);
}

if ( $display_dimensions && $product->has_dimensions() ) {
$product_attributes['dimensions'] = array(
'label' => __( 'Dimensions', 'woocommerce' ),
'value' => wc_format_dimensions( $product->get_dimensions( false ) ),
);
}

// Add product attributes to list.
$attributes = array_filter( $product->get_attributes(), 'wc_attributes_array_filter_visible' );

foreach ( $attributes as $attribute ) {
$values = array();

if ( $attribute->is_taxonomy() ) {
$attribute_taxonomy = $attribute->get_taxonomy_object();
$attribute_values   = wc_get_product_terms( $kproduct['id'], $attribute->get_name(), array( 'fields' => 'all' ) );

foreach ( $attribute_values as $attribute_value ) {
$value_name = esc_html( $attribute_value->name );

if ( $attribute_taxonomy->attribute_public ) {
$values[] = '<a href="' . esc_url( get_term_link( $attribute_value->term_id, $attribute->get_name() ) ) . '" rel="tag">' . $value_name . '</a>';
} else {
$values[] = $value_name;
}
}
} else {
$values = $attribute->get_options();

foreach ( $values as &$value ) {
$value = make_clickable( esc_html( $value ) );
}
}

$product_attributes[ 'attribute_' . sanitize_title_with_dashes( $attribute->get_name() ) ] = array(
'label' => wc_attribute_label( $attribute->get_name() ),
'value' => apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values ),
);
}
if ( ! empty( $product_attributes ) ) :
?>
<ul class="mb-0 text-end me-1">
<?php $i=0; foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : 
if($i<4): ?>
<li> <?php echo $product_attribute['label']; ?> : <?php echo str_replace( 'p>' , 'span>' , $product_attribute['value'] ); ?> </li>
<?php endif ;
$i += 1; endforeach; ?>
</ul>
<?php endif; ?>

</div>
</div>

