Support

Home Forums Event Espresso Premium Custom Functions File Issue with default Registration Notification Email

Custom Functions File Issue with default Registration Notification Email

Posted: August 8, 2019 at 1:34 pm


Renee deVilliers

August 8, 2019 at 1:34 pm

Hi,

I am editing the default email that sends – the approval pending Email Notification, and I thought I had done it correctly.

However when I test it, only SOME of the email body shows up in the email.

I don’t know why it is omitting parts of the email.

We discovered recently that even though we are selecting a CUSTOM email to be sent when someone registers, it is NOT always sending the selected email, but reverts to the default approval pending email, which I’d like to change to match the selected email we use in the drop down. That way it will not matter what they get – it will be the right email content.

But in editing the custom_functions.php file it doesn’t seem to output the entire body of the email.

This is the new code I have edited for the email:

// Override preapproval emails in Event Espresso 3
if (!function_exists('event_espresso_send_attendee_registration_approval_pending')) {

	function event_espresso_send_attendee_registration_approval_pending($registration_id) {
		global $org_options, $wpdb;
		do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
		//Get the event information
		$events = $wpdb->get_results("SELECT ed.* FROM " . EVENTS_DETAIL_TABLE . " ed
						JOIN " . EVENTS_ATTENDEE_TABLE . " ea
						ON ed.id = ea.event_id
						WHERE ea.registration_id='" . $registration_id . "'");

		foreach ($events as $event) {
			$event_id = $event->id;
			$event_name = stripslashes_deep($event->event_name);
			$event_desc = stripslashes_deep($event->event_desc);
			$display_desc = $event->display_desc;
			$event_identifier = $event->event_identifier;
			$reg_limit = $event->reg_limit;
			$active = $event->is_active;
			$send_mail = $event->send_mail;
			$conf_mail = $event->conf_mail;
			$email_id = $event->email_id;
			$alt_email = $event->alt_email;
			$start_date = event_date_display($event->start_date);
			$end_date = $event->end_date;
			$virtual_url = $event->virtual_url;
			$virtual_phone = $event->virtual_phone;
			$event_address = $event->address;
			$event_address2 = $event->address2;
			$event_city = $event->city;
			$event_state = $event->state;
			$event_zip = $event->zip;
			$event_country = $event->country;
			$location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
			$location_phone = $event->phone;
			$require_pre_approval = $event->require_pre_approval;

			$google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
		}

		//Build links
		$event_url = espresso_reg_url($event_id);
		$event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';

		$sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;

		if ($registration_id != '') {
			$sql .= " WHERE registration_id = '" . $registration_id . "' ";
		} elseif ($attendee_id != '') {
			$sql .= " WHERE id = '" . $attendee_id . "' ";
		} else {
			_e('No ID Supplied', 'event_espresso');
		}

		$sql .= " ORDER BY id ";
		$sql .= " LIMIT 0,1 "; //Get the first attendees details

		$attendees = $wpdb->get_results($sql);
		//global $attendee_id;

		foreach ($attendees as $attendee) {
			$attendee_id = $attendee->id;
			$attendee_email = $attendee->email;
			$lname = $attendee->lname;
			$fname = $attendee->fname;
			$address = $attendee->address;
			$address2 = $attendee->address2;
			$city = $attendee->city;
			$state = $attendee->state;
			$zip = $attendee->zip;
			$payment_status = $attendee->payment_status;
			$txn_type = $attendee->txn_type;
			$amount_pd = $attendee->amount_pd;
			$event_cost = $attendee->amount_pd;
			$payment_date = event_date_display($attendee->payment_date);
			$phone = $attendee->phone;
			$event_time = event_date_display($attendee->event_time, get_option('time_format'));
			$end_time = event_date_display($attendee->end_time, get_option('time_format'));
			$date = event_date_display($attendee->date);
			$pre_approve = $attendee->pre_approve;
		}
		$admin_email = $alt_email == '' ? $org_options['contact_email'] : $alt_email . ',' . $org_options['contact_email'];
		if (!empty($admin_email)) {
			$subject = __('New class registration to approve','event_espresso');
			$body = sprintf( __('Class/Event: %1$s <br /> Start Date: %2$s <br /> Start Time: %3$s <br /> Event ID: %4$s', 'event_espresso'), $event_name, $start_date, $event_time, $event_id );
			$body .= '<br /><br />';
			$body .= sprintf( __('Attendee name: %1$s %2$s', 'event_espresso'), $fname, $lname );
			$body .= '<br /><br />';
			$body .= __('In order to finalize this registration, you will need to login and approve the registration. For the event list go to: http://www.allaboutdogs.ca/wp-admin/admin.php?page=events', 'event_espresso');
			$email_params = array(
					'send_to' => $admin_email,
					'email_subject' => __($subject, 'event_espresso'),
					'email_body' => $body
			);
			event_espresso_send_email($email_params);
		}

		if (!empty($attendee_email)) {
			$subject = sprintf( __('%1$s Class Registration','event_espresso'), $event_name ) ;
$body = sprintf( __('Class/Event: %1$s <br /> Start Date: %2$s <br /> Start Time: %3$s <br /> Event ID: %4$s', 'event_espresso'), $event_name, $start_date, $event_time, $event_id );
            $body .= '<br /><br />';
$body = sprintf( __('Thank you for registering for %1$s which begins on %2$s at %3$s <br /> Your registration ID is: %4$s', 'event_espresso'), $event_name, $start_date, $event_time, $registration_id );
			$body .= '<br /><br />';
$body .= __('This email is a confirmation that we received your registration request and answers to our registration questions. This confirmation reserves a spot for your dog, however we want to ensure certain requirements are met, and the dogs are compatible within any given class or interaction scenarios that we offer At All About Dogs, so we would like to review your request.', 'event_espresso');
        $body .= '<br /><br />';
        $body .= __(' Once your registration has been reviewed and approved, you will receive an email from us that will include a link for you to complete payment for your registration. Please note that <strong>until payment is received your place in class is NOT SECURED</strong>. Payment completes the registration process and secures your class placement.','event_espresso');
             $body .= '<br /><br />';
                        $body .= __('Our waiver is required to be completed in order to finalize your registration along with your payment. Please <a href="http://www.allaboutdogs.ca/wp-content/uploads/AAD-General-Waiver.pdf">download our waiver</a> and complete it (either manually or digitally using Acrobat Reader Pro). Then, if filled out manually, please scan the completed waiver and submit by email or mail it to us using regular mail to: All About Dogs, 47 Gurney Cres., Toronto, ON M6B 1S9. Digitally signed and completed waivers in Acrobat can also be emailed.', 'event_espresso');
                         $body .= '<br /><br />';
                        $body = sprintf( __('We also require a copy of your vaccination record. Please also submit a photo copy/scan of the most recent vaccination record to us either via email or by mail with your waiver form. Note: all payment and paperwork must be submitted IN ADVANCE of the first class, and NOT brought on the first class. If you wish to provide us the waiver and vaccination records in person, please do so before %1$s.','event_espresso'), $start_date ) ;
             $body .= '<br /><br />';
            $body .= __(' Once payment is received, and all waiver and vaccination records are provided, your class spot is reserved for you.');
              $body .= '<br /><br />';
            			$body .= __('Thank you for choosing All About Dogs', 'event_espresso');
			$body .= '<br /><br />';		
			$body .= __('The All About Dogs Team<br/>~ Bring out the best in your dog so your dog can bring out the best in you! ~', 'event_espresso');
			$body .= '<br />';
			$body .= __('416-787-3647  /  www.allaboutdogs.ca', 'event_espresso');
				$email_params = array(
					'send_to' => $attendee_email,
					'email_subject' => __($subject, 'event_espresso'),
					'email_body' => $body
			);
			event_espresso_send_email($email_params);
		}
	}

}

This is the text it generates in the actual email received – FYI The subject text comes through correctly, but as you can see it is missing the first 5 paragraphs or so of the email content:

We also require a copy of your vaccination record. Please also submit a photo copy/scan of the most recent vaccination record to us either via email or by mail with your waiver form. Note: all payment and paperwork must be submitted IN ADVANCE of the first class, and NOT brought on the first class. If you wish to provide us the waiver and vaccination records in person, please do so before Wednesday, August 7, 2019.

Once payment is received, and all waiver and vaccination records are provided, your class spot is reserved for you.

Thank you for choosing All About Dogs

The All About Dogs Team
~ Bring out the best in your dog so your dog can bring out the best in you! ~
416-787-3647 / http://www.allaboutdogs.ca

++++++++++

Can you please help me figure out what is wrong with the custom file. I have put the old one back temporarily, but since we have issues with the custom email being sent, I’d really like to get this fixed asap.

Thanks!!!


Josh

  • Support Staff

August 8, 2019 at 1:46 pm

Hi,
I’ll refer you to the PHP manual:

https://www.php.net/manual/en/language.operators.string.php

A few examples where you didn’t concatenate the $body string follow:
https://slack-files.com/T02SY781D-FLVE5GKV1-294a15e4d2

https://slack-files.com/T02SY781D-FLVE2A1NF-8e13c9f76f


Renee deVilliers

August 9, 2019 at 9:25 am

Josh, I have little skill in php. I tried what you said and it broke the entire site and things were bad, very bad. Had to deactivate everything and reinstall EE and the custom files plugin, and reinstall old custom_function.php file used solidly for years prior to this edit. Any chance you can actually have a look at the entire php section and make sure nothing else is messed up in it and resend the correct version? I am no expert in php, but we HAVE to get this fixed because the CUSTOM EMAIL drop down selection that we use for EVERY SINGLE REGISTRATION does NOT always get emailed and it falls back to this default, and it needs to match the custom one, if we can get it to match then we don’t have to use custom one every time.

Can you please help.

Thanks


Josh

  • Support Staff

August 9, 2019 at 9:46 am

You tried what I said? I didn’t actually say to do anything specific, other than point you in the direction of the PHP manual, and point you to where you have a few errors in your code.

I’ll try to help you by pointing out a few more specific errors in your code and how they can be fixed. Please understand though, it’s not my place to support or rewrite code that was not developed by Event Espresso staff. Specific code change suggestions to follow in the next replies.


Josh

  • Support Staff

August 9, 2019 at 10:08 am

The first error is on this line:

$body = sprintf( __('Thank you for registering for %1$s which begins on %2$s at %3$s <br /> Your registration ID is: %4$s', 'event_espresso'), $event_name, $start_date, $event_time, $registration_id );

I can advise to change the above to:

$body .= sprintf(
	'Thank you for registering for %1$s which begins on %2$s at %3$s <br /> Your registration ID is: %4$s',
	$event_name,
	$start_date,
	$event_time,
	$registration_id
);

You’ll note that in the above change, the $body variable is no longer reset, and instead added to (or concatenated). Also, there’s no need to wrap your custom text with a localization function. Your code will be simpler to maintain without them. Finally, please note the formatting. When each variable is on its own line, your code will be easier to maintain/debug/read and so on.


Josh

  • Support Staff

August 9, 2019 at 10:26 am

The same problem occurs later with:

$body = sprintf( __('We also require a copy of your 
vaccination record. Please also submit a photo 
copy/scan of the most recent vaccination record 
to us either via email or by mail with your 
waiver form. Note: all payment and paperwork must 
be submitted IN ADVANCE of the first class, and 
NOT brought on the first class. If you wish to 
provide us the waiver and vaccination records in 
person, please do so before %1$s.','event_espresso
'), $start_date ) ;

I can advise to change to:

$body .= sprintf(
	'We also require a copy of your vaccination record. Please also submit a photo copy/scan of the most recent vaccination record to us either via email or by mail with your waiver form. Note: all payment and paperwork must be submitted IN ADVANCE of the first class, and NOT brought on the first class. If you wish to provide us the waiver and vaccination records in person, please do so before %1$s.',
	$start_date
);

In a nutshell, the $body variable was getting unintentionally reset a few times, which effectively deleted the first 5 paragraphs or so. A simplified example follows:

$body = 'I\'m the first paragraph!';
$body .= 'I\'m the second paragraph!';
$body .= 'I\'m the third paragraph!';
$body .= 'I\'m the fourth paragraph!';
$body = 'Sorry fellow paragraphs, I\'m <strong>now</strong> the first paragraph!';

The support post ‘Custom Functions File Issue with default Registration Notification Email’ 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.

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: closed

Updated by  Josh 4 months ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!