Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer sending duplicate invoice emails #94

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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