Skip to main content

How to Exclude Tagged Products from Klaviyo Abandoned Checkout Emails

  • May 22, 2026
  • 2 replies
  • 26 views

Claudia Howard
Contributor III
Forum|alt.badge.img+5

I previously used custom code inside a text block to exclude tagged products in Shopify from Abandoned Checkout flows (thanks to Joseph Hsieh for the original inspiration).

I’m now using Klaviyo’s newer HTML block for the same functionality.

I wanted to preserve:

  • excluding tagged products in Shopify from Abandoned Checkout emails
  • skipping the email if a product sells out before the first email sends
  • inheriting the template’s global style

Here’s the code to copy into the HTML block:
 

<div style="padding:20px;">

  {% for item in event.extra.line_items %}

    {% if not 'ac_exclude' in item.product.tags %}

      {% catalog item.product_id unpublished="cancel" %}

        <div style="padding:20px 40px;">

          <div style="text-align:center; margin:0 0 15px 0;">
            <a href="{{ event.extra.responsive_checkout_url }}">
              <img
                style="width:300px; max-width:100%; display:block; margin:0 auto;"
                src="{% if item.product.variant.images.0.src %}{{ item.product.variant.images.0.src }}{% else %}{{ item.product.images.0.src|missing_product_image }}{% endif %}"
                width="300"
                alt="{{ item.product.title }}"
              >
            </a>
          </div>

          <div style="text-align:center;">
            <p style="margin:0;">
              <a
                href="{{ organization.url }}/products/{{ item.product.handle }}"
                style="text-decoration:underline;"
              >
                {{ item.product.title }}
              </a>
            </p>
          </div>

        </div>

      {% endcatalog %}

    {% endif %}

  {% endfor %}

</div>

2 replies

Temi O.
Community Manager
  • Community Manager
  • May 26, 2026

@Claudia Howard Thanks for sharing this — really helpful to see the full code and the thinking behind each piece! 
 

As a general note here for context: Klaviyo's HTML block is the right place for this kind of custom logic. It gives you full control over your code, including Django template tags like {% for %}, {% if %}, and {% catalog %}. If you were previously using the source code view inside a text block for custom code, migrating to an HTML block is the way to go — especially since source code view is being removed from text blocks as part of the editor upgrade rollout.

Looking at your setup, you're covering the three key things well:
- Excluding tagged products — Your {% if not 'ac_exclude' in item.product.tags %} check will correctly filter out any Shopify products tagged with ac_exclude before they render. That should work as expected, and is a common pattern for keeping things like gift cards, warranties, or other non-standard items out of abandonment emails.
 

- Skipping the email for sold-out items — The {% catalog item.product_id unpublished="cancel" %} tag handles this perfectly. One thing worth noting for anyone reading through this: the unpublished="cancel" argument is all-or-nothing at the message level. If any looked-up product is unpublished at send time, the entire email gets cancelled — not just that one product. In an Abandoned Checkout context where you're already filtering by tag, this is usually the desired behavior, but it's good to be aware of. You can find more detail in the catalog lookup tag reference.

- Inheriting template styles — Since the HTML block sits inside your drag-and-drop template, your template-level styles (background colors, section spacing, etc.) will still apply around it. That said, the HTML block itself doesn't automatically inherit text styles the way a text block does — your inline styles on the <div>, <p>, and <a> tags are what control the look inside the block. If you want your font family, size, or link colors to match the rest of your template, you'll want to set those explicitly in your inline CSS within the block (which it looks you’ve done)!

One other thing I’d just like to mention: when previewing this in the editor, make sure your preview data source is set to Event (not Profile) and that you're selecting an actual Abandoned Checkout event. Otherwise the event.extra.line_items data won't populate and the block will appear empty.

Overall, your approach looks solid! The logic flow — loop through items, filter by tag, check catalog availability, then render — is a clean pattern that should work well in the HTML block.
As always, if you run into any rendering issues or need hands-on help with your specific account, please feel free to reach out to our Support team. You can create a ticket by clicking "Support" at the top right of any Klaviyo page! 


GabbyEsposito
Community Manager
Forum|alt.badge.img+12
  • Community Manager
  • May 26, 2026

Thanks for sharing ​@Claudia Howard ! And thanks for the awesome notes ​@Temi O.