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

global $labels;

$t_args = array(
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
    'number' => 'all',
    'meta_query' => array(
        array(
            'key' => 'irk_is_promotion',
            'value' => '1',
            'compare' => '=',
        ),
    ),
);
$terms = get_terms($t_args);
if (!count($terms)) {
    return null;
}
$total_products = count(
    get_posts(
        array(
            'post_type' => 'product',
            'post_status' => 'publish',
            'fields' => 'ids',
            'posts_per_page' => '-1',
        )
    )
);
$title = str_replace('{{total_count}}', $total_products, $title);
?>
<div class="promotion-categories">
    <div class="row">
        <?php foreach ($terms as $term): ?>
            <div class="term-<?php echo $term->term_id; ?> col">
                <a href="<?php echo get_term_link($term->term_id); ?>">
                    <?php echo irk_get_icon(get_term_meta($term->term_id, 'irk_promotion_icon', true)); ?>
                    <span class="category-name"><?php echo $term->name; ?></span>
                    <?php if ($show_count): ?>
                        <span class="category-quantity"><?php echo $term->count . ' ' . $labels->get_label('products'); ?></span>
                    <?php endif; ?>
                </a>
            </div>
        <?php endforeach; ?>
    </div>
</div>
