The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

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

enmincenminc Member
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
Comments
  • fc_adamfc_adam FoxyCart Team
    @enminc,

    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 }} {{ donation.name }}
    {% 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
    @enminc,

    We have a summary of the variables available in the templates on our wiki here: https://wiki.foxycart.com/v/2.0/templates/view_data. 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.