<?php
defined('ABSPATH') || exit('No Access!');

if (!is_product_category()) {
    return;
}

global $options, $labels;
$ht_slider_catalog_products_title = irk_get_head_tag('ht-slider-catalog-products-title', ['class' => 'title clearfix']);
$ht_slider_catalog_products = irk_get_head_tag('ht-slider-catalog-products', ['class' => 'title']);

$term = get_queried_object();
$post_in = get_term_meta($term->term_id, 'irk_slider_products', true);
if (!$post_in || !$options->get_option('catalog-products-slider')) {
    return;
}
$post_in = irk_generate_post__in($post_in);

$p_args = array(
    'post_type' => 'product',
    'posts_per_page' => -1,
    'post__in' => $post_in,
);
$products = new WP_Query($p_args);

$title = $options->get_option('catalog-products-slider-title');
$title = str_replace('{{title}}', woocommerce_page_title(false), $title);
?>
<div class="archive-products-slider widget-products-slider widget">
    <header class="header">
        <?php echo $ht_slider_catalog_products_title['open'] . '<span>' . esc_html(irk_translated_string($title)) . '</span>' . $ht_slider_catalog_products_title['close']; ?>
    </header>
    <div class="slider-inner">
        <div class="owl-carousel">
            <?php while ($products->have_posts()): ?>
                <?php
                $products->the_post();
                $product_id = $products->post->ID;
                $product = wc_get_product($product_id);
                ?>
                <div class="item">
                    <a href="<?php echo $product->get_permalink(); ?>" title="<?php echo $product->get_name(); ?>">
                        <div class="img-wrapper">
                            <?php echo $product->get_image('woocommerce_thumbnail', ['class' => 'img-fluid']); ?>
                            <?php //echo get_product_thumbnail( $product_id, 'woocommerce_thumbnail', [ 'class' => 'img-fluid' ] ); ?>
                        </div>
                        <?php echo $ht_slider_catalog_products['open'] . $product->get_name() . $ht_slider_catalog_products['close']; ?>
                        <?php echo $product->get_price_html(); ?>
                    </a>
                </div>
            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>
        </div>
    </div>
</div>