Skip Navigation

[Resolved] Conditional Statements in Email Notifications Not Working

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 7 replies, has 2 voices.

Last updated by julieP 7 years, 5 months ago.

Assisted by: Tia.

Author
Posts
#449886

I'm trying to create an email notification for a post form that changes content according to conditional statements but they're not working as expected.

I have a post form (create & edit versions) that contains an 'arrival time' and a 'collection time'. When a customer submits the form, its status is set to pending review. A variety of scenarios can present themselves regarding the arrival and collection times; the customer may put an incorrect time on the form to start with or either they or I may amend one or both of the times at a later date. So I've created a radio field called 'time types' with options of 'Both Accepted', 'Arrival Changed', 'Collection Changed', 'Neither Accepted', 'Arrival Amended', Collection Amended', Both Amended'. When a form is first submitted or if the customer amends the form later, I select one of the first four options, depending on whether the times are as agreed. If I amend either the arrival or collection time at a later date, I select one of the last three options.

I've built my conditional statements around the 'time types' field and the content of the email notification (which is the same for both the create and edit versions of the form) looks like this (with actual message text replaced for clarity):-

[wpv-conditional if="( $(wpcf-time-types) eq 'Accepted' )"]
<p>I'm pleased to inform you that your booking is now fully confirmed.</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Arrival Changed' )"]
<p>arrival time's been changed</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Collection Changed' )"]
<p>collection time's been changed</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Both Changed' )"]
<p>arrival & collection times have been changed</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Accepted' ) OR ( $(wpcf-time-types) eq 'Arrival Changed' ) OR ( $(wpcf-time-types) eq 'Collection Changed' ) OR ( $(wpcf-time-types) eq 'Both Changed' )"]
<p>general information if arrival/collection times not being amended by me after initial confirmation</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Arrival Amended' )"]
<p>this is why I've changed the arrival time</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Collection Amended' )"]
<p>this is why I've changed your collection time</p>
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-time-types) eq 'Both Amended' )"]
<p>this is why i've changed both your arrival & collection times</p>
[/wpv-conditional]

Can you see any reason why these statements shouldn't produce the output required please?

#450057

Tia

Thank you for contacting Toolset Support. I am happy to help you with this.

Please allow me time to read your initial post more carefully and test your recommendations. I will respond as soon as possible with feedback.

#450076

Hi Tia

Of course, no problem.

In the meantime, I thought you might be interested in a few tests I did this morning.

Instead of using various conditional statements inside a single email notification, I tried this:-

I set the initial confirmation to be sent when the post is published and this notification contains just the message and no conditionals. I then set up a new notification to be sent when custom field 'time-types' is amended with condition of 'arrival amended'. This works BUT it sends the email to the author 3 times! The first one contains the copy booking with the original arrival time and the next two contain the copy booking with the amended arrival time.

In some ways I'd prefer to be able to use the 'when custom fields are amended' option because I could set up a different notification for each variable and it would then be clearer. However, I think it's important to discover why the conditional statement way isn't working.

Let me know if you'd like me to post these latest findings in a new thread?

Thanks

#450812

Tia

No, that is okay. I will address that as well and let you know if a new thread needs to be opened if I can repeat the issue locally.

To make sure I understand the set up completely, the conditional fields are in the notification email body, correct? Just double checking I have it set up correctly and ready to test but want to make sure we match.

And from what I understand YOU change the status, not the user, correct? Do you use the native WordPress dashboard to do this or a frontend CRED form?

#450816

Hi Tia

Thanks for your help.

Yes, the conditional statements are in the notification email body.

Yes, it's me with Administrator role that changes the 'times-type' status and I'm using the WordPress dashboard.

#451895

Tia

Great, thank you. I am wrapping up on this today and we will find out what is going on. Please standby for feedback.

#452830

Tia
cred-line.jpg

For the CRED form we need to change $(wpcf-time-types) to [types field=‘time-types’ id=‘%%POST_ID%%’] as outlined below. I just double checked and was successful.

[wpv-conditional if="( [types field='time-types' id='%%POST_ID%%'] eq 'Accepted' )"]
<p>I'm pleased to inform you that your booking is now fully confirmed.</p>
[/wpv-conditional]

Please let me know if this resolves the issue or if it needs more investigation.

#453718

Hi Tia

Many thanks for your help on this - the conditional statements are now working.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.