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.

Custom email subjects for different categories


I know we can edit the email receipt template here

My question is: can we have a custom email subject for different categories?

  • fc_adamfc_adam FoxyCart Team

    It is possible to customise the email subject based on the transaction, by using some Twig in the template. We have some information about those on our wiki here for your reference:

    As an example of how you could approach it:
    {% set custom_subject = "" %}
    {% for item in items %}
    {% if item.category == "Category1" %}
    {% set custom_subject = 'Custom subject for Category 1' %}
    {% elseif item.category == "Category2" %}
    {% set custom_subject = 'Custom subject for Category 1' %}
    {% endif %}
    {% endfor %}

    {% if custom_subject != "" %}
    {{ custom_subject|fc_output_data('email_subject') }}
    {% endif %}
    That code will loop through the cart items, and set a custom subject depending on what products are in the cart. If multiple products are present, then it'll set it to whatever the last item's category is. You could modify that to set variables for what products are present in the cart, and then decide on the category based on the different combinations of categories. Then finally, if the custom_subject variable isn't empty, then it sets the subject accordingly. If it is still blank though, it doesn't set the subject and so the default subject will be used.
  • Thank you @fc_adam , I'll give it a go
  • alextorresalextorres Member
    edited November 2017
    Hello @fc_adam

    I'm having trouble concatenating a variable to an string to build the subject

    This is what I'm trying to do but it's giving me an error when I save the template and I'm not sure what's wrong

    {% set custom_subject = "PPX-" ~ {{ order_id }} ~ " " ~ {{ store_name }} ~ "Order " %}

    And this is the error
    Your template was not saved because there was an error in your Twig template syntax: A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "punctuation" of value "{" in "TEMP_email_template.twig" at line 4
    Your settings have not been saved.

    EDIT: nevermind, this

    {% set custom_subject = "PPX-" ~ order_id ~ " " ~ store_name ~ "Order " %}

    is not giving me an error anymore ^_^'
  • fc_adamfc_adam FoxyCart Team

    Glad you got it working! Yeah, as the set command is already a Twig command, you can just reference Twig variables directly within it like you've discovered.
Sign In or Register to comment.