On our WordPress website we are using the Events Manager Pro plugin. This allows us to create events. However we need to somehow send a thank you E-mail to the attending people 1 day after the event end date.
I have already written this up:
add_action( 'em_bookings_added', 'mail_after_completion' );
function mail_after_completion (){
global $wpdb;
/*Get the email of who booked */
$person_id = $wpdb->get_var("SELECT person_id FROM mbc_em_bookings ORDER BY booking_date DESC LIMIT 1");
$person_email = $wpdb->get_var( $wpdb->prepare("SELECT user_email FROM mbc_users WHERE ID = %s",$person_id));
/*Get the event finish date */
$event_id = $wpdb->get_var("SELECT event_id FROM mbc_em_bookings ORDER BY booking_date DESC LIMIT 1");
$event_end_date = $wpdb->get_var( $wpdb->prepare("SELECT event_end_date FROM mbc_em_events WHERE event_id = %s",$event_id));
/*Send E-mail to the person who just booked */
$to = '$person_email';
$subject = "Thank you for attending";
$content = "Thank you for attending the event at $event_end_date";
$status = wp_mail($to, $subject, $content);
}
?>
This function sends an E-mail to a person whenever they book an event. However I would like this to happen 1 day after the event completes. I've looked into CRON and wp_schedule_single_event()
a lot but can't seem to figure out how to properly use it.
If somebody could shed some light on this it would be greatly appreciated
Kind regards!
$to = '$person_email'
should be$to = $person_email
, otherwise you are literally trying to send to the string$person_email
(single vs double quotes)