less than a minute read • Updated 9 minutes ago
Add a link to the web receipt based on product category
How to show a link on the web receipt when the order contains products from a specific category.
If you'd like to add a link to the web receipt based on the category of items in the order, you can use this snippet to look through the items in the cart for any items with a specified category. If that category is found in the cart, you can display the link on your web receipt.
This particular example allows you to dynamically build a URL based on the order number. You can change it to a hardcoded URL if you wish to link to the same place every time.
You'll need to have created your category in the Categories section of the Foxy admin (https://admin.foxy.io) and assigned it to your products.
Step 1: Apply the snippet to your configuration
In the Foxy admin (https://admin.foxy.io), go to Settings > Receipts and edit the Custom template for web receipt, then look for this line: {% embed 'receipt.inc.twig' %}. After this line, you'll paste the following twig code:
html
{% block messaging %}
<!-- customized link message -->
{% set has_item_category = false %}
{% set category_link_url = 'http://www.yourdesiredlinkhere.com/' ~ order_id %}
{% for item in items %}
{% if item.category == 'Your category here' %}
{% set has_item_category = true %}
{% endif %}
{% endfor %}
{% if has_item_category %}
<div id="fc-messages" class="fc-receipt__section">
<div class="fc-alert fc-alert--success">
<a href="">This is your link</a>
</div>
</div>
{% endif %}
<!-- /customized link message -->
{% endblock %}Step 2: Customise conditions
You'll need to update the url variable "category_link_url" to your desired URL and the text "your_category_here" to what ever the category is that you assigned to the product. You'll also need to change "This is your link" to your desired text to display for the link.