1

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?

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.

0

Looks like you're missing the if conditional?

Try this:

{% if cart.eDate|date('D') in ['Tue'] %}
    Tuesday's discount!
{% endif %}
2
  • 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
    Dec 8 '20 at 5:22
  • 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
    Dec 8 '20 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.