Can I modify AC flow to only display four products if more are available?

  • 11 May 2024
  • 1 reply
  • 52 views

Badge

Actually, I can. But the case is more specific, and I need help, please.

Requirments:
1. Free products ($0) shouldn't appear in the email.
2. I need to display a maximum 4 products with price no matter if there are more than 4 with price available.
3. If the loaded products in the email are odd numbers, the first product should appear in a full-width column (1 per row) instead of 2x1 like the rest.

Example products in the flow:
1st product: $67
2nd product: $73
3rd product: $0
4th product: $0
5th product: $53
6th product: $0
7th product: $56
8th product: $134

My code:

{% for item in event.extra.line_items %}
{% if item.line_price != 0 %}
{% if not forloop.counter0 >= 4 %}

...HTML with product...

{% endif %}
{% endif %}
{% endfor %}

1. So products that are free ($0) shouldn't appear in the email; no problem - {% if item.line_price != 0 %}

2. I use {% if not forloop.counter0 >= 4 %} but it doesn't work perfect for me. I mean, it iterates to 4 and stops, which is correct. The problem is that in some cases, for example, the 3rd and 4th iterations are free products, but they have been counted from the looping. Then the looping stopped. Only the first and second products are loaded in the email even the flow contain 8 products. I have 5th, and 7th products that aren't $0.

So can I display products 1st, 2nd, 5th, and 7th? So maximum 4 products with price even there are more than 4 with price and couple without price?

3. Currently I have no ideas.

 


1 reply

Userlevel 7
Badge +60

Hey @mbtestmails 

Welcome to the community!

I have reached out to one of our email template experts to see if this is possible since this is a bit more complex. I will follow up as soon as I have an answer for you.

Reply