<p>For anyone interested in why this didn't work...It appears that you can't include a filter in the twig statement for discount formula conditions, at least not |date() as I was using. The error message in the CP isn't so great since it is valid twig syntax, but I totally get not using filters in this situation.</p>

CC BY-SA 4.0
2020-12-11T02:47:50.850Z
2020-12-11T02:47:50.850Z
cbad
<p>Looks like you're missing the <code>if</code> conditional?</p>
<p>Try this:</p>
<pre><code>{% if cart.eDate|date('D') in ['Tue'] %}
    Tuesday's discount!
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-12-08T05:22:36.410Z
Yea, that didn't work either, but thank you! I didn't have the 'if' because I was thinking the Order Condition Formula needed a boolean value to qualify the discount. The placeholder shows something like this: '@apple.com' in order.email
cbad
CC BY-SA 4.0
2020-12-08T15:30:03.753Z
Just to elaborate a bit further, my thinking was the Condition Formula would provide a conditional that Commerce would then wrap an if around when evaluating whether to apply the discount or not. Maybe that's flawed thinking?
cbad
CC BY-SA 4.0
2020-12-07T23:00:43.203Z
2020-12-07T23:00:43.203Z
Brad Bell
<p>I'm trying to add a condition for a discount. It involves a custom date field. I want to discount anything that falls on Tuesday. I can't seem to get the twig syntax right. I've tried these two:</p>
<pre><code>((cart.eDate|date('D')) == 'Tue')
((cart.eDate|date('D')) in ['Tue'])
</code></pre>
<p>I prefer the latter so I could add additional days if needed. Either of these work in templates. Is it because it is a custom field and the CP doesn't recognize it? Is there another approach?</p>

<plugin-craftcommerce>
Trouble with twig syntax for discount conditions
# Trouble with twig syntax for discount conditions

(Asked by: username_0 on 2020-12-07)

I'm trying to add a condition for a discount. It involves a custom date field. I want to discount anything that falls on Tuesday. I can't seem to get the twig syntax right. I've tried these two:
((cart.eDate|date('D')) == 'Tue')
((cart.eDate|date('D')) in ['Tue'])

I prefer the latter so I could add additional days if needed. Either of these work in templates. Is it because it is a custom field and the CP doesn't recognize it? Is there another approach?

**Tags:** plugin-craftcommerce

---

## 2 answers

### Answer by username_0 on 2020-12-11. Score: 1

For anyone interested in why this didn't work...It appears that you can't include a filter in the twig statement for discount formula conditions, at least not |date() as I was using. The error message in the CP isn't so great since it is valid twig syntax, but I totally get not using filters in this situation.


---

### Answer by username_1 on 2020-12-07. Score: 0

Looks like you're missing the if conditional?
Try this:
{% if cart.eDate|date('D') in ['Tue'] %}
    Tuesday's discount!
{% endif %}

> **Comments:**
> **username_0**: Yea, that didn't work either, but thank you! I didn't have the 'if' because I was thinking the Order Condition Formula needed a boolean value to qualify the discount. The placeholder shows something like this: '@apple.com' in order.email  
> **username_0**: Just to elaborate a bit further, my thinking was the Condition Formula would provide a conditional that Commerce would then wrap an if around when evaluating whether to apply the discount or not. Maybe that's flawed thinking?  

---

