/** * After the daily summary email gets sent, queue the next summary email for the next day */ public static function queue_daily_summary_email() { $next_send = get_option('fue_next_summary', false); $send_time = get_option('fue_daily_emails_time', '06:00 AM'); if (false === $next_send) { $next_send = strtotime(date('Y-m-d', current_time('timestamp')) . ' ' . $send_time); if (current_time('timestamp') > $next_send) { // already in the past. Set it for tomorrow $next_send += 86400; } update_option('fue_next_summary', $next_send); } else { update_option('fue_last_summary', current_time('timestamp')); update_option('fue_next_summary', $next_send + 86400); } $scheduler = Follow_Up_Emails::instance()->scheduler; $items = $scheduler->get_items(array('meta' => 'daily_summary', 'is_sent' => 0, 'status' => 1)); if (empty($items)) { // FUE will use the billing_email by default. Remove the hook to stop it from changing the email remove_filter('fue_insert_email_order', array($scheduler, 'get_correct_email')); $scheduler->queue_email(array('user_email' => FUE_Reports::get_summary_recipient_emails(), 'meta' => array('daily_summary' => true, 'email' => FUE_Reports::get_summary_recipient_emails(), 'subject' => __('Follow-up emails summary', 'follow_up_emails'), 'message' => ''), 'email_trigger' => 'Daily summary', 'order_id' => 0, 'product_id' => 0, 'send_on' => $next_send), null, true); update_option('fue_last_summary', current_time('timestamp')); update_option('fue_next_summary', $next_send + 86400); } }