这是关于对问题的评论。它需要在特定的元上运行,而不是在每次元值更新时运行mail函数。
您还需要相应地更改代码。
首先检查您的$meta_key
然后从$meta_value
. 在这些字段中写入条件并相应地触发邮件。
add_action(\'updated_post_meta\', \'send_email_on_job_complete\',10,4);
function send_email_on_job_complete($meta_id, $post_id, $meta_key, $meta_value)
{
$post_type = get_post_type($post_id);
if("jobs" !== $post_type) return;
if("job-status-1" !== $meta_key) return; //Check if currently updated meta key is meta key you want to check.Else return.
$job_status = types_get_field_meta_value("job-status-1",$post_id);
if($job_status == 1)
{
return;
}
else
{
$user_id = get_post_meta($post_id,"user_id",true);
$user_info = get_userdata($user_id);
$user_full_name = $user_info->display_name;
$user_email = $user_info->user_email;
//sending email from user to admin
$to_admin_email = get_option(\'admin_email\');
$subject_to_admin = \'JOB COMPLETED\';
$body_to_admin = \'Job is completed which is posted by \'.$user_full_name.\'.\';
$headers_to_admin = array(\'Content-Type: text/html; charset=UTF-8\');
//sending email from admin to user
$subject_to_user = \'JOB COMPLETED\';
$body_to_user = \'Your posted job is complete plz give review about it.\';
$headers_to_user = array(\'Content-Type: text/html; charset=UTF-8\');
wp_mail( $to_admin_email, $subject_to_admin, $body_to_admin, $headers_to_admin );
wp_mail( $user_email, $subject_to_user, $body_to_user, $headers_to_user );
}
}
像这样的。