Support

Home Forums Event Espresso Premium Can I stop individual datetime reminder emails from sending?

Can I stop individual datetime reminder emails from sending?

Posted: August 1, 2020 at 1:08 pm

Viewing 5 reply threads


Daniel

August 1, 2020 at 1:08 pm

Hello!

I have the need to stop some individual datetime reminder emails for a class from sending while allowing others through.

I have used customized shortcodes to create a wide range of new functionality in our reminder emails (and other emails) so kudos to you guys for creating such a flexible system. I am constantly amazed by what is possible!

For instance, here is one code snippet where we look up a meta value on an event and then insert a shortcode if it exists.


if ( $shortcode == '[CUSTOM_MAKEUP_CLASS_POLICY_SECTION_IF_MAKE_UP_CLASS]' ) {
		            // pull the meta value from the event post
					$makeup_message = '';
		            // these are field names in acf plugin
					$makeup_date = $event->get_post_meta('make_up_class_on_date_1', true);
					if ($makeup_date != '') {
						// run the custom shortcoder right from here
						$makeup_message = do_shortcode('[sc name="make-up-class-policy-short"]');
					}
				return $makeup_message;
	        }

So, I know there are datetime-specific and event-specific shortcodes… but can I make a registration-specific shortcode that can be applied to a shortcode like [RECIPIENT_EMAIL] that is normally in the TO field?

What I’d like to do is simply stop an email from sending based on a user’s registration question answers. For instance, if they choose “do not send me reminder emails” on our question form in checkout I want to stop the email from sending to them. I had an idea that I could customize the [RECIPIENT_EMAIL] to be something like [CUSTOM_RECIPIENT_EMAIL_BASED_ON_QUESTION] and then simply route the email to a “dead-letter” email address thereby stopping delivery of the email.

Is this possible to use a custom EVENT context shortcode in the TO field?
If not, is there another way to handle the actual sending / not-sending of the emails?

Thank you!
D


Tony

  • Support Staff

August 3, 2020 at 7:27 am

Hi Daniel,

So, I know there are datetime-specific and event-specific shortcodes… but can I make a registration-specific shortcode that can be applied to a shortcode like [RECIPIENT_EMAIL] that is normally in the TO field?

Sure you can.

Take a look in \event-espresso-core-reg\core\libraries\shortcodes\ and you’ll find a whole host of shortcode types.

[RECIPIENT_EMAIL] is a EE_Recipient_Details_Shortcodes shortcode so if you want to do the above you could add a shortcode to that library in pretty much the same way you have for (based on the above) datetimes and events.

You may also want to look into the EE_Primary_Registration_Details_Shortcodes library depending on the message contexts you are using.

Side note, you’re now getting into the a library that is usually passed an EE_Messages_Addressee object and pulls various bits of info from that as needed, take a close look at how the _parser() method for the 2 above library pull the data they need as you’ll need to do the same.

What I’d like to do is simply stop an email from sending based on a user’s registration question answers. For instance, if they choose “do not send me reminder emails” on our question form in checkout I want to stop the email from sending to them. I had an idea that I could customize the [RECIPIENT_EMAIL] to be something like [CUSTOM_RECIPIENT_EMAIL_BASED_ON_QUESTION] and then simply route the email to a “dead-letter” email address thereby stopping delivery of the email.

Just return an empty string '' as a message within an empty ‘To’ field is considered disabled by EE and will be dropped.

Is this possible to use a custom EVENT context shortcode in the TO field?

Possible, yes, but event-specific shortcodes won’t help you here unless I’m misunderstanding.

Event shortcodes would be things like [EVENT_ID], [EVENT_NAME], [EVENT_DESCRIPTION] and from your question, you need something specific to the registrant itself (an answer from the registration form), which means you need a recipient based shortcode.


Daniel

August 3, 2020 at 8:13 am

Great! I was missing the insight that each “section” of the email has its own class that is passed parser data. The EE_Recipient_Details_Shortcodes is the class I was looking for – thanks!

I added this to the shortcodes after parser filter (not sure if I need all of the “instanceof” ternary operations at the beginning, but I can confirm that this code works when added to a ‘FHEE__EE_Shortcodes__parser_after’ hook and added to the list of shortcodes in ‘FHEE__EE_Shortcodes__shortcodes’):


if ( $lib instanceof EE_Recipient_Details_Shortcodes ) {
// grab the registration object to customize the TO field
  $addee = $data instanceof EE_Messages_Addressee ? $data : NULL;
  $addee = $extra_data instanceof EE_Messages_Addressee ? $extra_data : $addee;
  $registration_obj = $addee instanceof EE_Messages_Addressee && $addee->reg_obj instanceof EE_Registration ? $addee->reg_obj : NULL;

  //Check we do now actually have the registration_obj.
  if ( !empty( $registration_obj ) ) {
    // look for the custom shortcodes
     if ( $shortcode == '[CUSTOM_TO_ADDRESS_ROUTING_BY_REGISTRATION_INFO]' ) {
        $to_address = 'example@example.com';
        return $to_address;
    }
  }
}

Any feedback on this code welcome!
TY


Tony

  • Support Staff

August 3, 2020 at 8:44 am

Your current code can’t do anything without an EE_Registration object so rather than checking for !empty() I’d do something like:

if (! $registration_obj instanceof EE_Registration) {
    return $parsed;
}

You can also check for an EE_Attendee if you start to do anything with that but at least with the above, you already know any code after that can safely use $registration_obj as an EE_Registration object.

What you have should work anyway so up to you, now it’s just a case of pulling a value for the registration question and doing whatever you need from there.


Daniel

August 20, 2020 at 8:25 am

Hello!

I am back to this thread again with an issue that I am having trouble approaching.

Some background:
I have an event that is set up with AM, PM, and fullday classes. Customers can purchase a ticket that entitles them to attend 3,4, or 5 half-day or full-day. They indicate which specific sessions they want to attend by answering questions in the checkout.

We composed the event this way to keep the ticket chooser as simple as possible. It works well.

Now, I am trying to customize the reminder emails to dead-letter only reminder emails when they don’t match up with the specific timeslots indicated in the checkout questions. Basically, dead-letter any emails that are trying to remind a customer about a datetime they didn’t sign up for.

It seems that I need to get access to the specific datetime object that triggered the email. Only then will I be able to extract the correct info to do the question data comparison.

I am able to access the recipient info and I can get generic datetime info through the registration, but I need to get access to the exact data in the datetime object that triggered the reminder email.

Am I going about this in the wrong way?
Am I missing something obvious? (I scoured the EE code).

Thank you!
D


Tony

  • Support Staff

August 20, 2020 at 3:33 pm

Have you checked how the AUEN add-on pulls the specific datetime object it is generating data for?

If not, take a look in:

\eea-automated-upcoming-event-notifications\domain\services\messages\EE_Specific_Datetime_Shortcodes.lib.php

I think the _parser() method in that shortcode library should help point you in the right direction and specifically the get_specific_datetime() method.

Viewing 5 reply threads

The support post ‘Can I stop individual datetime reminder emails from sending?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso