基本上,您需要的是发送这些提醒的日常任务,因为您将使用WP Cron。我不会进入实际构建电子邮件的逻辑(使用您的代码)。以下是基本设置:
if ( ! wp_next_scheduled( \'quote_reminder_hook\' ) ) {
wp_schedule_event( time(), \'daily\', \'quote_reminder_hook\' );
}
add_action( \'quote_reminder_hook\', \'send_quote_reminder\' );
function send_quote_reminder() {
$args = array(
\'post_type\' => \'quote\',
);
$loop = new WP_Query($args);
while($loop->have_posts()){
$loop->the_post();
$days = "30";
$eventName = types_render_field( "event-name", array( \'raw\' => true));
$email = types_render_field( "email-user", array( \'raw\' => true));
$eventdate = types_render_field( "event-date", array( \'raw\' => true) );
$newDate = date("d-m-Y", strtotime($eventdate));
$date = strtotime (\'-30 days\', strtotime ($newDate));
$date = date (\'d-m-Y\', $date);
$today = date("d-m-Y");
$balance = types_render_field( "remaining", array( \'raw\' => true) );
if (!empty($balance) && $today === $date ) {
$to = $email;
$subject = "Payment reminder";
$content = \'Please pay the final payment here\';
/*$from = "no-reply@website.com";
$headers = "From:" . $from;*/
wp_mail($to,$subject,$content,$headers);
}
}
}
如果你有很多引用,我建议你把它们分成几批,或者把事件设置为每小时一次,这样它就不会超时,也不会占用你的服务器资源。
我建议您将cron设置为从系统任务调度器运行(这里有一个指南https://developer.wordpress.org/plugins/cron/hooking-into-the-system-task-scheduler/)
Cron引用https://developer.wordpress.org/plugins/cron/
当做