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.

Little help with Twig

KadriKadri Member
in Help edited May 2013
I've been trying to figure out this on my own but still coming up with nothing so I figured I'd ask for help.

I have a custom field in my checkout called 'message'. What I want to do is hide something when a value is entered into the message field, and not hide it when it's left empty. Is it possible to do and how?

  • KadriKadri Member
    Wanted to clarify a little bit. I wanna lets say, not display the order total info if there is something in the message box. But I wanna show it when it's left empty.
  • fc_adamfc_adam FoxyCart Team

    Are you wanting to hide the order total information on the receipt, or on the checkout, based on if the message custom field is completed or not?
  • KadriKadri Member
    Just on the receipt. Basically the idea is if it's been sent as a gift to hide the total cost fields on the receipt (cause that gets printed to go into the box) but if it hasn't been sent as a gift to show them as normal.
    I'm not sure if this is even possible. As of right now I've used the datafeed to generate my own custom receipt for if it's a gift.

    I would still very much like to know if and how this is possible to achieve via twig.
  • fc_adamfc_adam FoxyCart Team

    It is possible with Twig. Essentially you'd have this code towards the top of your receipt template:
    {% set has_message = false %}
    {% for custom_field in custom_fields %}
    	{% if == "message" and custom_field.value != "" %}
    		{% set has_message = true %}
    	{% endif %}
    {% endfor %}

    Then whatever you want to hide, you can set it to only show if has_message is true, like this:
    {% if has_message == true %}
    // Code in here
    {% endif %}

    I haven't tested that code, but it should work.

    Note though, that by doing this you're also hiding the totals from the customers who will be viewing this receipt after the transaction completes. You know your target audience better than we do - but personally if I've just purchased something as a gift, I'd want confirmation on what I've just spent. Something to keep in mind anyway.
  • KadriKadri Member
    It's good to know how to do something like this for the future!
    I will just keep the gift receipts populated on our server via datafeed. That way the buyer and seller can still view the original receipt but the gift recipient will recieve a nice little gift receipt with the box.

    thank you for taking time to post this!
Sign In or Register to comment.