Make Category Receipt Emails Only Include That Category's Products

If you'd like to set category-specific receipt emails that only include products from that specific category, read on. This can be useful for notifying multiple vendors or providers of an order, but without including the rest of the order details.

We'll focus on the text-only email receipt for now, but the same basic steps can be used for an html-formatted email.

Step 1: Get the Starting Template

Get a copy of the latest cart template from the Foxy template github repo: https://github.com/FoxyCart/2.0-templates

The text email template is here: https://raw.githubusercontent.com/FoxyCart/2.0-templates/master/cart.inc.txt.twig

Copy that into your text editor, and save it somewhere so you have it for reference later.

Step 2: Modify the Template

At the top of the file, add this:

{% set emailCategory = "blank" %}

Set blank to match the category code for the category in question.

Once that's in your text editor, locate this line:

{% for item in items %}

That loops through the items array. We just want to get rid of products that don't match a specific criteria. In this case, the categoryCode that we set earlier:

{% for item in items %}
{% if item.category == emailCategory %} {# Ignore any products in different categories. #}

Then further down, find the closing endfor, so we can add our endif above it. This is a little trickier. Find this code:

{% endif %}
  * {{ config.lang.cart_quantity|pad(15)|raw }} {{ item.quantity }}
  * {{ config.lang.cart_price|pad(20)|raw }} {{ item.price|money_format }}{% if item.quantity > 1 and item.price_each > 0 %} ({{ item.price_each|money_format }} {{ config.lang.cart_each|raw }}{% if (((item.price_each * 10000) % 100) != 0) %}... {{ item.price_each }}{% endif %}){% endif %}

{% endfor %} {# item loop #}
{{ config.lang.cart_subtotal|pad(24)|raw }} {{ total_item_price|money_format }}
{% if has_future_products %}

And add one extra line, like this:

{% endif %}
  * {{ config.lang.cart_quantity|pad(15)|raw }} {{ item.quantity }}
  * {{ config.lang.cart_price|pad(20)|raw }} {{ item.price|money_format }}{% if item.quantity > 1 and item.price_each > 0 %} ({{ item.price_each|money_format }} {{ config.lang.cart_each|raw }}{% if (((item.price_each * 10000) % 100) != 0) %}... {{ item.price_each }}{% endif %}){% endif %}

{% endif %} {# category check #}
{% endfor %} {# item loop #}
{{ config.lang.cart_subtotal|pad(24)|raw }} {{ total_item_price|money_format }}
{% if has_future_products %}

Step 3: Tweak and Test

What you've added is just the cart portion. You'll probably want to add some additional text, or potentially tweak things further. Then, of course, copy your template into the appropriate admin text email area on the category page in the admin.

You can easily test new emails by clicking the “email” link on a transaction in the admin, so just pick a test transaction and send emails after you tweak your template.

Site Tools