Context:
1) User submits an invoice via front end form
2) User receives email with submission details
2b) Internal (billing dept.) receives similar email noting the new invoice
The code:
Function 1: acf/save post; check for true/false field; IF false, fire wp_mail(). IF TRUE, bail on the mail function. The T/F indicates whether this email has been sent ever (once only).
$has_been_saved = $_POST['acf']['field_599dcb7c607d2'];
if($has_been_saved == 1) {
return;
}
<< Run all the wp_mail() stuff. >>
Function 2: IF TRUE/FALSE == 0, update_field TRUE
$has_been_saved = $_POST['acf']['field_599dcb7c607d2'];
if($has_been_saved !== 1) {
update_field('field_599dcb7c607d2', true, $post_id);
}
This works great!
Here’s the part I can’t seem to sort out:
Context:
1) When pay period is ending, internal employee logs in to ‘issue payment’
2) Once payment is issued, fire wp_mail() indicating a check has been cut.
The means of indicating is “Payment Issued” is another acf_form on the CPT invoice including a DATE field. Once selected and submitted, this should run through a similar check as above — IF there’s an issued date AND T/F == false (indicating the payment issued email hasn’t ever been sent) run wp_mail. THEN update_field() T/F to TRUE to prevent this mail from sending again.
I don’t fully grasp when the acf_form sends in relation to acf/save_post.
update_fields() is working here but can’t seem to get a passed check against the fields to run wp_mail.
To summarize –
When acf_form submitted, save_post() check T/F for “mail has been sent”, if FALSE, send mail then update_field to TRUE. If already TRUE, bail on the mail.
Is there a better way to run through this logic?
Cheers!