Add a link to the web receipt based on item 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 desired category in the Categories section of the admin, and linked the categories to your product. Go here for more details.

Step 1: Apply the snippet to your configuration

You can apply the snippet below within the “receipt” section of your store's FoxyCart administration - you'll need to select the “if you like, choose a default template:” option to enable the custom receipt template field and look for this line: {% embed 'receipt.inc.twig' %}. After this line, you'll paste the following twig code:

{% block messaging %}
    {{ parent() }}
    <!-- 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="{{ category_link_url }}">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.

Site Tools