> ## Documentation Index
> Fetch the complete documentation index at: https://discountkit.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Filtering discounts

> Filter discounts by method, markets, customer tags, and cart state in your Liquid templates

Discount Kit Live surfaces up to 25 of the discounts you've tagged `dk:live` — both automatic and code-based. It doesn't filter by who's viewing the page, what market they're in, or what's already in their cart. Use these inline Liquid patterns to do that filtering in your theme.

<Note>
  The `max_reward_percent` and `max_reward_cents` scalar metafields automatically exclude targeted discounts (test mode, GWP, customer-tagged, market-specific, and code-based). If you use the scalar metafields for badges, no filtering is needed. The patterns below are only needed when working with the full `discounts` array.
</Note>

## Filtering by Method (Automatic vs Code)

Each discount in the `discounts` array carries a `method` field of either `'automatic'` or `'code'`. Split your rendering accordingly:

```liquid theme={null}
{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}

{%- comment -%} Auto-applied discounts: render plain badges {%- endcomment -%}
{% for discount in discounts %}
  {% if discount.method == 'automatic' %}
    <span class="badge">{{ discount.maximum_reward_value | round }}% OFF</span>
  {% endif %}
{% endfor %}

{%- comment -%} Code discounts: render code chips with copy button {%- endcomment -%}
{% for discount in discounts %}
  {% if discount.method == 'code' and discount.code != blank %}
    <span class="code-chip">
      {{ discount.maximum_reward_value | round }}% off with <code>{{ discount.code }}</code>
    </span>
  {% endif %}
{% endfor %}
```

## Hiding Codes Already Applied to the Cart

When a shopper has already entered a discount code, advertising it again is noise. Compare the code against `cart.discount_applications` to detect what's in play:

```liquid theme={null}
{%- comment -%}
  Build a lookup of applied codes once. Liquid has no Sets, so we use a
  comma-joined string and `contains`. Comma wrappers prevent partial matches
  (e.g. `SALE` shouldn't match `SUMMERSALE10`).
{%- endcomment -%}
{% capture applied_codes %}
  {%- for application in cart.discount_applications -%}
    {%- if application.type == 'discount_code' -%},{{ application.code | downcase }},{%- endif -%}
  {%- endfor -%}
{% endcapture %}

{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}

{% for discount in discounts %}
  {% if discount.method == 'code' and discount.code != blank %}
    {% assign needle = ',' | append: discount.code | downcase | append: ',' %}
    {% unless applied_codes contains needle %}
      <span class="code-chip">Use <code>{{ discount.code }}</code></span>
    {% endunless %}
  {% endif %}
{% endfor %}
```

<Note>
  Shopify normalises discount codes case-insensitively at checkout, so we `downcase` both sides of the comparison. The `cart.discount_applications` array is populated server-side on each page render, so this works without any JavaScript.
</Note>

## Filtering Test Mode Discounts

Discounts in test mode only apply to customers tagged `test`. Use the `test` field to exclude them from your storefront display.

```liquid theme={null}
{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}

{% for discount in discounts %}
  {% unless discount.test %}
    <div class="badge">
      {{ discount.maximum_reward_value | round }}% OFF
    </div>
  {% endunless %}
{% endfor %}
```

## Filtering by Market

Discounts can be restricted to specific Shopify Markets. Filter to show only those applicable to the customer's current market.

### How It Works

* Uses `localization.market.handle` to identify the current market
* Empty `included_markets` means the discount applies to all markets
* If `included_markets` has values, the current market must match
* Checks `excluded_markets` to exclude specific markets

### Complete Example

```liquid theme={null}
{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}
{% assign current_market = localization.market.handle %}
{% assign eligible_discount = nil %}

{% for discount in discounts %}
  {% assign is_eligible = true %}

  {% comment %} Check included markets {% endcomment %}
  {% if discount.included_markets.size > 0 %}
    {% assign market_match = false %}
    {% for market in discount.included_markets %}
      {% if market == current_market %}
        {% assign market_match = true %}
        {% break %}
      {% endif %}
    {% endfor %}
    {% unless market_match %}
      {% assign is_eligible = false %}
    {% endunless %}
  {% endif %}

  {% comment %} Check excluded markets {% endcomment %}
  {% if discount.excluded_markets.size > 0 %}
    {% for market in discount.excluded_markets %}
      {% if market == current_market %}
        {% assign is_eligible = false %}
        {% break %}
      {% endif %}
    {% endfor %}
  {% endif %}

  {% comment %} Take first eligible discount {% endcomment %}
  {% if is_eligible %}
    {% assign eligible_discount = discount %}
    {% break %}
  {% endif %}
{% endfor %}

{% if eligible_discount %}
  <div class="badge">
    {{ eligible_discount.maximum_reward_value }}% OFF
  </div>
{% endif %}
```

## Filtering by Customer Tags

Discounts can target specific customers using tags. Filter to show only those applicable to the current customer.

### How It Works

* **Included Tags**: Customer must have at least one tag from `included_customer_tags`
* **Excluded Tags**: Customer must not have any tag from `excluded_customer_tags`
* **Not Logged In**: Customers who aren't logged in are excluded from tag-targeted discounts

### Complete Example

```liquid theme={null}
{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}
{% assign eligible_discount = nil %}

{% for discount in discounts %}
  {% assign is_eligible = true %}

  {% comment %} Check included customer tags {% endcomment %}
  {% if discount.included_customer_tags.size > 0 %}
    {% if customer %}
      {% assign has_required_tag = false %}
      {% for required_tag in discount.included_customer_tags %}
        {% if customer.tags contains required_tag %}
          {% assign has_required_tag = true %}
          {% break %}
        {% endif %}
      {% endfor %}
      {% unless has_required_tag %}
        {% assign is_eligible = false %}
      {% endunless %}
    {% else %}
      {% comment %} Not logged in but tags required {% endcomment %}
      {% assign is_eligible = false %}
    {% endif %}
  {% endif %}

  {% comment %} Check excluded customer tags {% endcomment %}
  {% if discount.excluded_customer_tags.size > 0 %}
    {% if customer %}
      {% for excluded_tag in discount.excluded_customer_tags %}
        {% if customer.tags contains excluded_tag %}
          {% assign is_eligible = false %}
          {% break %}
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endif %}

  {% comment %} Take first eligible discount {% endcomment %}
  {% if is_eligible %}
    {% assign eligible_discount = discount %}
    {% break %}
  {% endif %}
{% endfor %}

{% if eligible_discount %}
  <div class="vip-badge">
    {{ eligible_discount.discount_title }}
  </div>
{% endif %}
```

## Combined Filtering

Combine both market and customer tag checks for complete eligibility filtering:

```liquid theme={null}
{% assign discounts = product.metafields.app--9549316097--discount_kit.discounts.value %}
{% assign current_market = localization.market.handle %}
{% assign eligible_discount = nil %}

{% for discount in discounts %}
  {% assign is_eligible = true %}

  {% comment %} Check market eligibility {% endcomment %}
  {% if discount.included_markets.size > 0 %}
    {% assign market_match = false %}
    {% for market in discount.included_markets %}
      {% if market == current_market %}
        {% assign market_match = true %}
        {% break %}
      {% endif %}
    {% endfor %}
    {% unless market_match %}
      {% assign is_eligible = false %}
    {% endunless %}
  {% endif %}

  {% if discount.excluded_markets.size > 0 %}
    {% for market in discount.excluded_markets %}
      {% if market == current_market %}
        {% assign is_eligible = false %}
        {% break %}
      {% endif %}
    {% endfor %}
  {% endif %}

  {% comment %} Check customer tag eligibility {% endcomment %}
  {% if is_eligible and discount.included_customer_tags.size > 0 %}
    {% if customer %}
      {% assign has_required_tag = false %}
      {% for required_tag in discount.included_customer_tags %}
        {% if customer.tags contains required_tag %}
          {% assign has_required_tag = true %}
          {% break %}
        {% endif %}
      {% endfor %}
      {% unless has_required_tag %}
        {% assign is_eligible = false %}
      {% endunless %}
    {% else %}
      {% assign is_eligible = false %}
    {% endif %}
  {% endif %}

  {% if is_eligible and discount.excluded_customer_tags.size > 0 %}
    {% if customer %}
      {% for excluded_tag in discount.excluded_customer_tags %}
        {% if customer.tags contains excluded_tag %}
          {% assign is_eligible = false %}
          {% break %}
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endif %}

  {% if is_eligible %}
    {% assign eligible_discount = discount %}
    {% break %}
  {% endif %}
{% endfor %}

{% if eligible_discount %}
  <div class="badge">
    {{ eligible_discount.maximum_reward_value }}% OFF
  </div>
{% endif %}
```

## Next Steps

* Learn how to [access discount data](/live/storefront-data)
* View complete [examples](/live/examples)
* Check the full [reference](/live/reference)
