• Resolved grebos

    (@grebos)


    Hi, is there a way to send an automatic email to the owner of an event (I use the front end form with many different owners) at the end of an event as a reminder for a feedback

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    you can try option under events > settings > emails > booking email templates > email event owner

    We were interested in this ‘request feedback after course end date’ feature too.

    @angelo, your suggestion I think is invalid as the reminder only works before the start of the course, not after. That’s a new feature request I believe.

    Thread Starter grebos

    (@grebos)

    I have a similar problem, since I haven’t activated the booking stuff, the “booking email template” tab isn’t shown in my settings menu and even when activating, I didn’t see the option (or at least I didn’t see it). Is there a template which could to be adapted to setup this email triggered by the event_end_date? Don’t worry I know you are not allowed to help me with coding stuff, but giving me a starting hint, would be nice ??

    Hi all,

    This isn’t a feature of Events Manager so it would require some custom coding.

    If you want to send the same email to every event owner, one way to do it would be to use a daily cron job to run a custom PHP script which checks if any events ended that day and, if so, send email to the event owner.

    If you want to send a different email to different event owners, you could start with the same idea but you’d need to add extra coding to work out which email to send to where and so on.

    You might also need to add an admin page to save the different versions of the email, etc. Now it’s getting complicated ??

    An alternative might be to use an additional plugin that will let you email groups of users. It might be one of those could be used to cut down on the amount of custom coding required, or even eliminate it completely.

    Thread Starter grebos

    (@grebos)

    Hi, I implemented now a barebone email reminder function with no user interface and stuff like that. It works with WP Cron which has its issues written down here, but it should work how it is.
    It should be possible to implement this with a nice user interface and placeholders for the email text… but I’m not planing to do this.
    I recommend the WP Crontrol plugin tho activate and deactivate the function (Hook name is my_email_reminder_hook)

    
    register_activation_hook(__FILE__, 'my_activation');
    
    function my_activation() {
    	if ( ! wp_next_scheduled( 'my_email_reminder_hook' ) ) {
    	  wp_schedule_event( time(), 'hourly', 'my_email_reminder_hook' );
    	}
    }
    
    add_action( 'my_email_reminder_hook', 'my_email_reminder_function' );
    
    function my_email_reminder_function() {
    	date_default_timezone_set('europe/berlin');
    	$startTime = time();
    	$lastTimeChecked = $startTime;
    	
    	
    	//Set the directory how you want
    	$lastTimeChekedFileDirectory = plugin_dir_path( __FILE__ )."lastTimeCheckedFile.txt";
    
    	if(file_exists ( $lastTimeChekedFileDirectory )){
    		$lastTimeChekedFile = fopen($lastTimeChekedFileDirectory, "r") or die("Unable to open file!");
    		$lastTimeChecked = fread($lastTimeChekedFile,filesize($lastTimeChekedFileDirectory));
    		fclose($lastTimeChekedFile);
    	}
    	
    	//Get all Events occuring between those two dates. The Formatting to dates is needet since scope only takes dates and not time as input
    	// --> This could probably be done by adapting this code and making a custom scope according to the tutorial here:
    	// https://wp-events-plugin.com/tutorials/create-your-own-event-scope/
    	// but like this it also works
    	
    	$lastDateCheckd = date('Y-m-d',$lastTimeChecked);
    	$today = date('Y-m-d',$startTime);
    	
    	$eventArray = EM_Events::get(array('scope'=>$lastDateCheckd.','.$today));
    	
    	foreach($eventArray as $EM_Event){
    		$eventStartTime = $EM_Event->event_start_time;
    		$eventEndTime = $EM_Event->event_end_time;
    		
    		$eventStartDate = $EM_Event->event_start_date;
    		$eventEndDate = $EM_Event->event_end_date;
    		
    		$allDayEvent = $EM_Event->event_all_day;
    		
    		$realEventEndTime;
    		
    		//The reminder for all day events and events with no duration comes at midnight (evening) of the end date
    		if(($eventStartDate == $eventEndDate && $eventStartTime == $eventEndTime ) || $allDayEvent == 1){
    			$realEventEndTime = strtotime($eventEndDate)+ 24*60*60;  //+24h (in seconds) otherwise it would come at midnight in the morning of the end date)
    		}
    		else{
    			$realEventEndTime = strtotime($eventEndDate.$eventEndTime);
    		}
    		
    		//Test if event has endet since last time checked and now
    		if($realEventEndTime >= $lastTimeChecked && $realEventEndTime < $startTime){
    			//Get some variables to use in the mail
    			$eventOwner = get_user_by('id',$EM_Event->event_owner);
    			$ownerEmail = $eventOwner->user_email;
    			$ownerFirstName = get_user_meta($EM_Event->event_owner,'first_name',false)[0];
    			$eventName = $EM_Event->event_name;
    			
    			$emailTitle = "Feedback for $eventName";
    			$emailText = 
    "Hi $ownerFirstName 
    
    Some text ... your event $eventName has endet ...
    
    Please give a feedback under following link...
    
    This is an automatically generated e-mail";
    
    			//send the mail
    			wp_mail( $ownerEmail, $emailTitle, $emailText);
    		}
    	}
    	$myfile = fopen($lastTimeChekedFileDirectory, "w") or die("Unable to open file!");
    	fwrite($myfile, $startTime);
    	fclose($myfile);
    }
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Automatic email after event to owner’ is closed to new replies.