我有一个带有自定义字段的帖子类型报价,我想创建一个通知,向电子邮件地址集发送电子邮件提醒。当日期条件匹配时发送It提醒。我写了这个函数脚本。
function set_mail_html_content_type() {
return \'text/html\';
}
function notification_fields(){
// Get the \'Profiles\' post type
$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;*/
$status = wp_mail($to,$subject,$content,$headers);
add_filter( \'wp_mail_content_type\', \'set_mail_html_content_type\' );
return $status;
remove_filter( \'wp_mail_content_type\', \'set_mail_html_content_type\' );
}
}
wp_reset_query();
//return;
}
add_action( \'customemail_fields\', \'notification_fields\',10, 2 );