Skip to content

Commit

Permalink
send notification and thank you to sponsor when their invoice has bee…
Browse files Browse the repository at this point in the history
…n paid
  • Loading branch information
timiwahalahti committed Sep 21, 2023
1 parent e4f6df9 commit d3e05c4
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ function mark_invoices_as_paid( $sent_invoices, $paid_invoices ) {
if ( in_array( (int) $invoice->_wcbsi_qbo_invoice_id, $paid_invoices, true ) ) {
update_invoice_status( $invoice->ID, 'paid' );
notify_organizer_status_changed( $invoice->ID, 'paid' );
notify_sponsor_invoice_paid( $invoice->ID );
}
}
}
Expand Down Expand Up @@ -403,6 +404,41 @@ function notify_organizer_status_changed( $invoice_id, $new_status ) {
}
}

/**
* Send notification and thank you to sponsor when their invoice has been paid.
*
* @param integer $invoice_id
*/
function notify_sponsor_invoice_paid( $invoice_id ) {
if ( POST_TYPE !== get_post_type( $invoice_id ) ) {
return;
}

$sponsor_id = get_post_meta( $invoice_id, '_wcbsi_sponsor_id', true );
$to = is_email( get_post_meta( $sponsor_id, '_wcpt_sponsor_email_address', true ) );
if ( empty( $to ) ) {
return;
}

$sponsor_first_name = get_post_meta( $sponsor_id, '_wcpt_sponsor_first_name', true );
$wordcamp = get_wordcamp_post();
$wordcamp_name = get_bloginfo( 'name' );
$subject = "Your payment for {$wordcamp_name} has been received";
$headers = array(
"From: {$wordcamp_name} <support@wordcamp.org>",
"Reply-To: {$wordcamp->meta['E-mail Address'][0]}",
);

$message = sprintf( __( 'Hi %s,', 'wordcamporg' ), $sponsor_first_name ) . "\r\n\r\n";
$message .= sprintf( __( 'The invoice for %s has been marked as paid. Thank you for supporting the event!', 'wordcamporg' ), $wordcamp_name ) . "\r\n\r\n";
$message .= __( 'We made the sponsor wrangler aware of this and they will contact you about next steps!', 'wordcamporg' ) . "\r\n\r\n";
$message .= __( 'If you have any questions, please reply to let us know.', 'wordcamporg' ) . "\r\n\r\n";
$message .= __( 'Best regards', 'wordcamporg' ) . "\r\n";
$message .= sprintf( __( '%s team' ), $wordcamp_name );

wp_mail( $to, $subject, $message, $headers );
}

/**
* Get the name of the sponsor for a given invoice
*
Expand Down

0 comments on commit d3e05c4

Please sign in to comment.