Я пытаюсь отправить письмо с помощью функции wp_mail
и подключить его к save_post
.Как я могу проверить это, если это новое сообщение или оно просто обновляет сообщение?Я пробовал обновить параметр save_post, но всегда давал мне логический true
ответ.Мне нужно только отправить его, если это новое сообщение после публикации.Возможно ли это?
Вот мой код:
add_action( 'save_post', 'dt_email_client_new', 13, 3 );
function dt_email_client_new( $post_id, $post, $update ) {
$post_type = get_post_type($post_id);
if($post_type != 'dt_appointments'){
return;
}
if ( wp_is_post_revision( $post_id ) ) {
return;
}
// Stop WP from clearing custom fields on autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
// Prevent quick edit from clearing custom fields
if (defined('DOING_AJAX') && DOING_AJAX)
return;
remove_action( 'save_post', 'dt_email_client_new', 13, 3 );//this will avoid duplicate emails
//how can I check if its new post or update?
$get_first_name = get_post_meta($post_id, 'first_name', true);
$get_last_name = get_post_meta($post_id, 'last_name', true);
$get_date_time = get_post_meta($post_id, 'appointment_date_time', true);
$get_email = get_post_meta($post_id, 'email', true);
$get_doctor_id = get_post_meta($post_id, 'doctor', true);
$get_phone = get_post_meta($post_id, 'phone', true);
$user_info = get_userdata( $get_doctor_id );
$firstname = $user_info->first_name;
$lastname = $user_info->last_name;
$get_sched_date_format = date('F d, Y', strtotime($get_date_time));
$get_sched_time_format = date('H:i A', strtotime($get_date_time));
$to = $get_email;
$headers = array('Content-Type: text/html; charset=UTF-8','From: Test <sample@gmail.com>');
$subject = 'sample subj here...';
$body = '<p><strong>Hi '.$get_first_name.',</strong></p>
<p style="margin: 0px;">Your appointment request has been confirmed. Please proceed to ......</p>
<p></p>';
wp_mail( $to, $subject, $body, $headers );
}