I am working on some automated emails. I am fairly new to add_action and do_action. I am having a tough time understanding it. The site in question has number goals set up that people reach over time. I want to send them an email when they hit the goal. The code below will send that email when the post is updated but that won't work. I put it there just to make sure the email sends out. I don't know what add_action I should use. What reference should I be looking for to do this?
function emailNotificationSuccess($post_id) {
if( ( $_POST['post_status'] == 'publish' ) && ( $goalsupport === $totalsupport ) ) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
$totalsupport = countSupportForAll($post->ID);
$goalsupport = get_post_meta( $post->ID, 'sj_campaign_goal', true );
$supporter_email = get_post_meta( $post_id, 'sj_campaign_email', true );
$message = "Hi ".$author->display_name.",
Congrats! You have reached your goal!
Your , ".$post->post_title." is a success!
".get_permalink( $post_id )."
";
wp_mail($supporter_email, "You just reached your goal!", $message);
}
}
add_action('post_updated', 'emailNotificationSuccess');