less than a minute read • Updated 39 minutes ago
Display conditional content on the web receipt
How to show custom HTML on the web receipt only when specific conditions are met, such as a product from a particular
You can use Twig’s context variable to run logic that only applies on the receipt, combined with a loop over items to check what’s actually in the order — for example, to show different content depending on which product category was purchased.
Steps
{% if context == 'receipt' %}
{% set hasWholesale = false %}
{% for item in items %}
{% if item.category == 'WHOLESALE' %}
{% set hasWholesale = true %}
{% endif %}
{% endfor %}
{% if hasWholesale %}
<h1>Success!</h1>
{% endif %}
{% endif %}{# context == receipt #}
Notes
Wrapping the logic in
{% if context == 'receipt' %}keeps it from running on the cart or checkout, since those templates share the same underlying Twig data.Swap the condition inside the loop (
item.category,item.code,item.name, etc.) to match on whatever criteria you need — category is just one example.