Code
/**
* when an invoice post is saved update balance and total
*/
add_action( 'save_post_invoices', function( $post_id, $post, $update ) {
if ( (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || wp_is_post_revision($post_id) || $update ) {
return;
}
$account = get_field('invoice_account', $post_id);
$users = get_field('account_users', $account->ID);
if ( $users ) {
foreach ( $users as $user ) {
if ( in_array('sendinvoice', $user['account_user_options']) ) {
$to = $user['account_user']['user_email'];
$subject = 'New Invoice';
$body = 'Hi ' . $user['account_user']['user_firstname'] . ', <br><br>A new invoice has been posted to your account.<br><br>Hauss Designs<br>314.427.4955<br><a href="https://haussdesigns.com">haussdesigns.com</a>';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
// $headers[] = 'From: RGE Rewards';
wp_mail( $to, $subject, $body, $headers );
}
}
}