Skip to main content
Solved

Conditionally show a message for unpublished products in flows


Forum|alt.badge.img+5

Hi!

I’m trying to create a browse abandonment flow email that always displays a product, regardless of its stock status, but conditionally shows a message if the product is unpublished (e.g., “A new restock soon!”).

I’ve referred to this community post

where unpublished="cancel" is used to stop the email. However, I’d like to achieve the following instead:

  • Always send the email.
  • Show the product and display a message if it’s unpublished.

Could you please guide me on the correct property or method to achieve this behavior?
Thank you for your support!

Best answer by Christiannoerbjerg

Hi ​@Woodhope 

Thank you for posting in the Community!

As ​@ArpitBanjara mentioned. You would need to wrap the dynamic table in a if/else statement. I think to code above would work. 

If it doesn’t then you could try with the following code:

{% catalog event.ProductID unpublished="cancel" %}
    <a href="{{ catalog_item.url }}">
        <img src="{{ catalog_item.featured_image.full.src }}" style="width: 200px;" width="200px" alt="Product Image" />
    </a>
    {% if catalog_item.unpublished %}
        <p>A new restock soon!</p>
    {% endif %}
{% endcatalog %}

That have worked for another previous client of ours - So it could possible also work for you :-)

Hope that helps! :-) 

Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov

View original
Did this topic or the replies in the thread help you find an answer to your question?

10 replies

ArpitBanjara
Principal User I
Forum|alt.badge.img+36
  • Principal User I
  • 371 replies
  • January 10, 2025

Hey ​@Woodhope 

in the source code of the dynamic block, just add the below code

{% catalog event.ProductID unpublished="cancel" %}
    <a href="{{ catalog_item.url }}">
        <img src="{{ catalog_item.featured_image.full.src }}" style="width: 200px;" width="200px" />
    </a>
    {% if catalog_item.unpublished %}
        <p>A new restock soon!</p>
    {% endif %}
{% endcatalog %}

what this will do is that if the item is in stock it will show the product, however if its not it will show a message as you see above “A new restock soon!” 

You might have to change the above code depending on what all things you need in the dynamic block, for example - product name, product price etc. the above code is for reference. 


I hope this helps and thank you for sharing your question here in the community.

Cheers

Arpit


Christiannoerbjerg
Expert Problem Solver II
Forum|alt.badge.img+12

Hi ​@Woodhope 

Thank you for posting in the Community!

As ​@ArpitBanjara mentioned. You would need to wrap the dynamic table in a if/else statement. I think to code above would work. 

If it doesn’t then you could try with the following code:

{% catalog event.ProductID unpublished="cancel" %}
    <a href="{{ catalog_item.url }}">
        <img src="{{ catalog_item.featured_image.full.src }}" style="width: 200px;" width="200px" alt="Product Image" />
    </a>
    {% if catalog_item.unpublished %}
        <p>A new restock soon!</p>
    {% endif %}
{% endcatalog %}

That have worked for another previous client of ours - So it could possible also work for you :-)

Hope that helps! :-) 

Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov


Forum|alt.badge.img+5
  • Author
  • Contributor IV
  • 7 replies
  • January 10, 2025

Thank you both for your helpful answers. I do have a problem though. It seems that when I use unpublished="cancel", the email gets skipped entirely, which defeats the purpose of the conditional logic in the rest of the code.

My goal is to always send the email and display a specific message only if the product is unpublished. Could you clarify if this approach is possible and why unpublished="cancel" was suggested in this case?

Thank you again for your support!


Romoke
Contributor III
Forum|alt.badge.img+2
  • Contributor III
  • 5 replies
  • January 10, 2025

Hi ​@Woodhope 

Thank you for reaching out with this interesting use case! It’s great to see you working on a dynamic and customer-centric email flow. Here’s how you can achieve your goal of displaying a product regardless of stock status while conditionally showing a message for unpublished products:

  1. Always Send the Email:

    • Ensure your email flow is not interrupted by product availability settings. This can typically be controlled by avoiding any filters in the flow trigger that halt emails for out-of-stock products.
  2. Display the Product Information Dynamically:

    • Use dynamic data placeholders (e.g., variables from Klaviyo’s product feed or your Shopify integration) to pull in product details.
  3. Show Conditional Messaging for Unpublished Products:

    • Leverage Klaviyo’s conditional formatting or Shopify’s metafields to determine the product’s status. For example:

       

      liquid

      Copy code

      {% if product.published == false %} A new restock soon! {% else %} Check out this product! {% endif %}

    • This logic ensures that the appropriate message is displayed based on the product's status.

  4. Test Your Flow:

    • Before activating the flow, test it with different product scenarios (in stock, out of stock, unpublished) to ensure the email displays correctly in all cases.

If you need further guidance or specific steps to set this up in your email tool, feel free to share more details about your current setup, and I’ll be happy to assist!

Looking forward to seeing your innovative flow in action. 😊

Best regards,

Romoke

Klaviyo & Shopify  Expert


Forum|alt.badge.img+5
  • Author
  • Contributor IV
  • 7 replies
  • January 10, 2025

Thanks a lot for your solution! Unfortunately it doesn’t work: using this code, the phrase is shown for every products, even the ones that are out of stock


Romoke
Contributor III
Forum|alt.badge.img+2
  • Contributor III
  • 5 replies
  • January 10, 2025

Hi @Woodhope,

Thank you for your feedback, and I truly appreciate the clarification! Let’s refine the solution to ensure it works as intended and displays the correct message only for unpublished products while allowing out-of-stock products to still show. Here’s an updated approach:

Refined Solution to Your Use Case

1. Adjust Conditional Logic for Product States

The issue seems to be that the code isn't differentiating unpublished products from out-of-stock ones. To fix this, we’ll include specific conditions for both states.

In Klaviyo, use the following logic in your email template:

 

liquid

Copy code

{% if product.published == false %} <p>A new restock soon!</p> {% elsif product.inventory_quantity > 0 %} <p>Check out this product: {{ product.name }}</p> <a href="{{ product.url }}">Shop Now</a> {% else %} <p>Currently out of stock, but more on the way!</p> {% endif %}

Explanation of the Code:

  • product.published == false: Checks if the product is unpublished and displays the restock message.
  • product.inventory_quantity > 0: Ensures the product is shown only if it’s in stock.
  • else: Catches any remaining cases (e.g., out-of-stock products) and shows a placeholder message.

2. Testing with Real Data

To ensure this logic behaves as expected:

  • Step 1: Select products in different states: unpublished, in stock, and out of stock.
  • Step 2: Preview the email for each product state to confirm the correct message is displayed.
  • Step 3: If testing in Klaviyo, use their preview function with dynamic data or send test emails.

3. Advanced Alternative (Using Metafields)

If your product data includes metafields (from Shopify or another integration), you can use a custom metafield to better differentiate unpublished products. For instance:

  • Add a metafield called restock_status to indicate when a product is unpublished.
  • Update your logic to include this field:
 

liquid

Copy code

{% if product.metafields.restock_status == "unpublished" %} <p>A new restock soon!</p> {% elsif product.inventory_quantity > 0 %} <p>Check out this product: {{ product.name }}</p> <a href="{{ product.url }}">Shop Now</a> {% else %} <p>Currently out of stock, but more on the way!</p> {% endif %}

Next Steps

Please test this updated approach, and let me know how it performs. If you still encounter issues, feel free to share additional details about the setup (e.g., how product data is being passed from Shopify to Klaviyo), and I’ll be happy to assist further.

Looking forward to hearing your results! 😊

Best regards,
Romoke
Klaviyo & Shopify Expert


Forum|alt.badge.img+5
  • Author
  • Contributor IV
  • 7 replies
  • January 10, 2025

Hi Romoke, and thank you again. Unfortunately, it still doesn’t work, the code appears to be broken and it shows a yellow alert in the Klaviyo preview. It looks like Klaviyo is unable to detect the different status between publishd and unpublished. As a reference, I attach the event property for the viewed product event

 


ArpitBanjara
Principal User I
Forum|alt.badge.img+36
  • Principal User I
  • 371 replies
  • January 11, 2025

Hey ​@Woodhope 

its difficult to investigate further without looking at how events are coming in your preview. I feel the other answers posted above are mostly Chat-gpt responses, I would suggest you connect with Klaviyo support for additional support as they will be able to look more into detail by accessing your email.

Best of luck

Arpit

 


Christiannoerbjerg
Expert Problem Solver II
Forum|alt.badge.img+12

Hi ​@Woodhope 

Did you get to solve the issue? 

If not, i would be glad to help you online, if you have time today or in the coming week? 

If it suits your schedule, then just invite me for a meeting with the following e-mail: Christian@segmento.dk :-) 

Christian Nørbjerg Enger
Partner & CPO
Web: Segmento.dk
LinkedIn: @christianfromsegmento
Voldbjergvej 22b, 8240 Risskov


Forum|alt.badge.img+5
  • Author
  • Contributor IV
  • 7 replies
  • January 23, 2025

Hi Christian,

Thanks so much for reaching out and offering to help, I really appreciate it! Sorry for the delayed reply, I was on holiday.

I’ve managed to sort out the issue for now changing the strategy a bit, but I’ll definitely keep you in mind if anything comes up in the future. Thank you again