Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Is it possible to add select order information to a category email

I represent a non-profit that takes in both retail and donations at times on the same order. I have a "Donation" category that sends out an email if any of their items in their order happen to be a donation item. However at this time that email is a generic "Thank You For Your Donation"

The Wish would be to allow for those items that are a donation to be included in this email.

Example Scenario:

Customer Buys - Coffee Cup ($5 retail item), Donation ($10 donation item), Sponsorship ($20 donation item)

Donation Category Email -

"Thank You for Your Donation of $30"
Tax Deductible Donation #1: $10 Donation
Tax Deductible Donation #2: $20 Sponsorship
  • fc_adamfc_adam FoxyCart Team

    Good question. The category email templates support Twig just like our other templates do - so you can create any custom Twig logic you need. The category email will include all products in the transaction by default - so to determine the donation products specifically, you'd need to loop through and find just those from the donation category. For example:
    {% set donations = [] %}
    {% set total_donation = 0 %}
    {% for item in items %}
    {% if item.category == "Donation" %}
    {% set donations = donations|merge([item]) %}
    {% set total_donation = total_donation + item.price %}
    {% endif %}
    {% endfor %}

    {% if total_donation > 0 %}
    {% set custom_subject = 'Thank you for your donation of $' ~ total_donation %}
    {{ custom_subject|fc_output_data('email_subject') }}
    {% endif %}

    {% for donation in donations %}
    Tax Deductible Donation #{{ loop.index }}: {{ donation.price|money_format }} {{ }}
    {% endfor %}
    That would set a custom email subject for the category email to include the donated amount - and list out each of the donations included in the transaction.

    I hope that helps!
  • enmincenminc Member
    Thank you Adam. I assumed the loop would be needed but wasn't sure about global access to the order.

    Is there somewhere in the docs that I overlooked that notes all these (ex: items == 'your cart items')? I assume the customer info is also available.

    Is it safe to say vars in any given tpl or include can be mixed and matched in the other?
  • fc_adamfc_adam FoxyCart Team

    We have a summary of the variables available in the templates on our wiki here: It covers each page, and there are some variations in what's available between the cart, checkout and receipt/emails - but it's generally additive, in that what's available on the cart, will be then available on the checkout, which will then be available on the receipts. There are some exceptions - but hopefully that page should help clarify that.

    In terms of the category emails - they have access to the same data that the normal receipt emails have access to, so the same template logic from those can be copied over.
Sign In or Register to comment.