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

global $options, $labels;
$ht_catalog_subcat = irk_get_head_tag('ht-catalog-subcat', ['class' => 'term-name']);

$terms = get_terms([
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
    'parent' => get_queried_object_id()
]);
$count = count($terms);
$i = 0;
?>
<?php if (is_array($terms) && $count): ?>
    <div class="subcategories-list">
        <div class="categories-title"><?php esc_attr_e($labels->get_label('categories')); ?></div>
        <div class="row">
            <?php foreach ($terms as $term): ?>
                <?php
                $thumbnail_id = get_term_meta($term->term_id, 'thumbnail_id', true);
                $thumbnail_id = intval($thumbnail_id) ? $thumbnail_id : $options->get_option('placeholder-image');
                ?>
                <div class="item item-<?php echo $i; ?>">
                    <a href="<?php echo get_term_link($term, 'product_cat'); ?>" class="term term-<?php echo $term->term_id; ?>">
                        <?php
                        if ($thumbnail_id) {
                            echo wp_get_attachment_image($thumbnail_id, 'woocommerce_thumbnail', false, ['class' => 'img-fluid']);
                        } else {
                            echo wc_placeholder_img();
                        }
                        ?>
                        <?php echo $ht_catalog_subcat['open'] . $term->name . $ht_catalog_subcat['close']; ?>
                        <span class="term-count"><?php echo number_format($term->count); ?></span>
                    </a>
                </div>
                <?php if ($i == 6 && $count > 7): ?>
                    <div class="item others-categories">
                        <a href="#" class="term">
                            <div class="count">+<?php echo $count - 7; ?></div>
                            <div class="term-name"><?php esc_attr_e($labels->get_label('others-categories')); ?></div>
                        </a>
                    </div>
                <?php endif; ?>
                <?php $i++; ?>
            <?php endforeach; ?>
        </div>
    </div>
<?php endif;