Reminder email
-
I tried setting up a simple reminder email (by starting wp-cron) but it didn’t work. Is there another solution?
// === REMINDER === update_post_meta($booking_id, '_creavibc_reminder_sent', '0');// === REMINDER FUNCTIONALITY ===
define(‘CREAVIBC_REMINDER_ENABLED’, true);function creavibc_send_reminders() {
if (!CREAVIBC_REMINDER_ENABLED) return;global $wpdb; $now = current_time('mysql'); $reminder_threshold = date('Y-m-d H:i:s', strtotime('+24 hours')); $bookings = $wpdb->get_results(" SELECT p.ID, pm_date.meta_value as booking_date, pm_time.meta_value as booking_time, pm_name.meta_value as customer_name, pm_email.meta_value as customer_email, pm_service.meta_value as service_id FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm_date ON p.ID = pm_date.post_id AND pm_date.meta_key = '_creavibc_booking_date' LEFT JOIN {$wpdb->postmeta} pm_time ON p.ID = pm_time.post_id AND pm_time.meta_key = '_creavibc_booking_time' LEFT JOIN {$wpdb->postmeta} pm_name ON p.ID = pm_name.post_id AND pm_name.meta_key = '_creavibc_booking_name' LEFT JOIN {$wpdb->postmeta} pm_email ON p.ID = pm_email.post_id AND pm_email.meta_key = '_creavibc_booking_email' LEFT JOIN {$wpdb->postmeta} pm_service ON p.ID = pm_service.post_id AND pm_service.meta_key = '_creavibc_service_id' LEFT JOIN {$wpdb->postmeta} pm_reminder_sent ON p.ID = pm_reminder_sent.post_id AND pm_reminder_sent.meta_key = '_creavibc_reminder_sent' WHERE p.post_type = 'creavibc_booking' AND p.post_status = 'publish' AND CONCAT(pm_date.meta_value, ' ', pm_time.meta_value) BETWEEN '$now' AND '$reminder_threshold' AND (pm_reminder_sent.meta_value IS NULL OR pm_reminder_sent.meta_value = '0') "); foreach ($bookings as $booking) { $service_title = get_the_title($booking->service_id); $subject = "[REMINDER] " . $service_title . " - Appointment Tomorrow"; $message = "Hi " . $booking->customer_name . ",\n\nThis is a reminder for your " . $service_title . " appointment tomorrow at " . $booking->booking_time . ".\n\nSee you soon!"; wp_mail($booking->customer_email, $subject, $message); update_post_meta($booking->ID, '_creavibc_reminder_sent', '1'); }}
if (CREAVIBC_REMINDER_ENABLED) {
add_action(‘creavibc_daily_reminder_cron’, ‘creavibc_send_reminders’);
if (!wp_next_scheduled(‘creavibc_daily_reminder_cron’)) {
wp_schedule_event(time(), ‘daily’, ‘creavibc_daily_reminder_cron’);
}
}
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.