Skip to content

Commit

Permalink
Merge pull request #94 from dparker1005/limit-invoice-emails
Browse files Browse the repository at this point in the history
No longer sending duplicate invoice emails
  • Loading branch information
dparker1005 committed Aug 11, 2023
2 parents 56d3acf + d89a1ca commit 7353667
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pmpro-pay-by-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,14 +729,25 @@ function pmpropbc_confirmation_message( $confirmation_message, $invoice ) {
*/
function pmpropbc_send_invoice_email( $morder ) {

// Only worry about this if the order status was changed to "success"
if ( 'check' === strtolower( $morder->payment_type ) && 'success' === $morder->status ) {
// Only worry about this if this is a check order that is now in "success" status.
if ( 'check' !== strtolower( $morder->payment_type ) || 'success' !== $morder->status ) {
return;
}

$recipient = get_user_by( 'ID', $morder->user_id );
// Check order meta to see if an invoice email has already been sent for this order.
if ( function_exists( 'get_pmpro_membership_order_meta' ) && get_pmpro_membership_order_meta( $morder->id, 'pmpropbc_invoice_email_sent', true ) ) {
return;
}

$invoice_email = new PMProEmail();
$invoice_email->sendInvoiceEmail( $recipient, $morder );
}
$recipient = get_user_by( 'ID', $morder->user_id );

$invoice_email = new PMProEmail();
$invoice_email->sendInvoiceEmail( $recipient, $morder );

// Update order meta to indicate that an invoice email has been sent.
if ( function_exists( 'update_pmpro_membership_order_meta' ) ) {
update_pmpro_membership_order_meta( $morder->id, 'pmpropbc_invoice_email_sent', true );
}
}

add_action( 'pmpro_updated_order', 'pmpropbc_send_invoice_email', 10, 1 );
Expand Down

0 comments on commit 7353667

Please sign in to comment.