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


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.

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 2 months ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!
[gravityform id=80 title=false description=false ajax=false]
<div class='gf_browser_unknown gform_wrapper' id='gform_wrapper_80' ><form method='post' enctype='multipart/form-data' id='gform_80' action='/topic/can-i-stop-individual-datetime-reminder-emails-from-sending/'> <div class='gform_body'><ul id='gform_fields_80' class='gform_fields top_label form_sublabel_below description_below'><li id='field_80_1' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_1' >First name<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_text'><input name='input_1' id='input_80_1' type='text' value='' class='medium' aria-required="true" aria-invalid="false" /></div></li><li id='field_80_2' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_2' >Email address<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_email'> <input name='input_2' id='input_80_2' type='email' value='' class='medium' aria-required="true" aria-invalid="false" /> </div></li><li id='field_80_3' class='gfield gfield_contains_required field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' >GDPR Agreement<span class='gfield_required'>*</span></label><div class='ginput_container ginput_container_checkbox'><ul class='gfield_checkbox' id='input_80_3'><li class='gchoice_80_3_1'> <input name='input_3.1' type='checkbox' value='I consent to have this website store my submitted information so they can respond to my inquiry.' id='choice_80_3_1' /> <label for='choice_80_3_1' id='label_80_3_1'>I consent to have this website store my submitted information so they can respond to my inquiry.</label> </li></ul></div></li><li id='field_80_4' class='gfield gform_validation_container field_sublabel_below field_description_below gfield_visibility_visible' ><label class='gfield_label' for='input_80_4' >Comments</label><div class='ginput_container'><input name='input_4' id='input_80_4' type='text' value='' autocomplete='off'/></div><div class='gfield_description' id='gfield_description_80_4'>This field is for validation purposes and should be left unchanged.</div></li> </ul></div> <div class='gform_footer top_label'> <input type='submit' id='gform_submit_button_80' class='gform_button button' value='Download Now' onclick='if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} ' onkeypress='if( event.keyCode == 13 ){ if(window["gf_submitting_80"]){return false;} if( !jQuery("#gform_80")[0].checkValidity || jQuery("#gform_80")[0].checkValidity()){window["gf_submitting_80"]=true;} jQuery("#gform_80").trigger("submit",[true]); }' /> <input type='hidden' class='gform_hidden' name='is_submit_80' value='1' /> <input type='hidden' class='gform_hidden' name='gform_submit' value='80' /> <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' /> <input type='hidden' class='gform_hidden' name='state_80' value='WyJbXSIsIjBiNjdjZjkyMDUzOWUxOWY5Y2NiZjIwMzM4YjA1Mjk4Il0=' /> <input type='hidden' class='gform_hidden' name='gform_target_page_number_80' id='gform_target_page_number_80' value='0' /> <input type='hidden' class='gform_hidden' name='gform_source_page_number_80' id='gform_source_page_number_80' value='1' /> <input type='hidden' name='gform_field_values' value='' /> </div> </form> </div><script type='text/javascript'> jQuery(document).bind('gform_post_render', function(event, formId, currentPage){if(formId == 80) {} } );jQuery(document).bind('gform_post_conditional_logic', function(event, formId, fields, isInit){} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [80, 1]) } ); </script>
[i]
[i]