<?php

/**
 * The template for displaying product content within loops
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.6.0
 */

defined('ABSPATH') || exit;

global $product;

// Ensure visibility.
if (empty($product) || !$product->is_visible()) {
	return;
}

$product_classes = array('col-12', 'product-col');

switch (esc_attr(wc_get_loop_prop('columns'))) {
	case 2:
		array_push($product_classes, 'col-md-6');
		break;
	case 3:
		array_push($product_classes, 'col-xl-4', 'col-md-6');
		break;
	case 4:
		array_push($product_classes, 'col-lg-3', 'col-md-6');
		break;
}
?>

<div class="<?php echo implode(' ', $product_classes); ?>">
	<div <?php wc_product_class('product-box', $product); ?>>
		<a class="product-box-img" href="<?php the_permalink();  ?>">
			<?php
			do_action('woocommerce_before_shop_loop_item_title');

			$gal_img_ids = $product->get_gallery_image_ids();

			if (!empty($gal_img_ids)) {
				$gal_img_url = wp_get_attachment_image_src($gal_img_ids[0], 'full')[0];
				if ($gal_img_url) {
			?>
					<div class="product-box-img__hov">
						<img class="product-box-img__img-hov" src="<?php echo esc_url($gal_img_url); ?>">
					</div>
			<?php
				}
			}
			?>
		</a>
		<div class="product-box-desc">
			<h3 class="product-box-desc__h"><?php the_title(); ?></h3>
			<?php
			$product_desc = get_field('produkt_desc', $product->get_id());

			if ($product_desc) {
			?><div class="product-box-desc__p">
					<?php echo wp_kses_post($product_desc); ?></div><?php
												}
													?>

			<div class="product-box-desc__price">
				<?php do_action('woocommerce_after_shop_loop_item_title'); ?>
			</div>

			<?php if ($product->get_price_html() && !$product->is_type('variable')) { ?>
				<a class="product-box__add-to-cart add_to_cart_button ajax_add_to_cart" data-quantity="1" data-product_id="<?php echo get_the_ID(); ?>" href="?add-to-cart=<?php echo get_the_ID(); ?>"><span class="icon"></span></a>
			<?php } ?>
		</div>


		<a href="<?php the_permalink(); ?>" class="product-box__link"></a>
	</div>
</div>