Skip to content

Instantly share code, notes, and snippets.

@rvdsteege
Last active March 11, 2019 11:28
Show Gist options
  • Save rvdsteege/19ac676eed4160801e4fbe1ad34059ac to your computer and use it in GitHub Desktop.
Save rvdsteege/19ac676eed4160801e4fbe1ad34059ac to your computer and use it in GitHub Desktop.
Pronamic Pay status update notice by email.
<?php
// Add below code to functions.php of your WordPress theme.
/**
* Pronamic Pay status update notice.
*
* @param Payment $payment The payment.
* @param bool $can_redirect Whether or not to redirect.
* @param string $old_status Old paymet status.
* @param string $new_status New payment status.
*/
function pronamic_pay_status_update_notice( $payment, $can_redirect, $old_status, $new_status ) {
// Statuses to trigger notices for.
$trigger_statuses = array(
'Cancelled',
'Expired',
'Failure',
);
if ( ! in_array( $new_status, $trigger_statuses, true ) ) {
// Status not in trigger statuses.
return;
}
/*
* Send unsuccessful payment notice.
*/
// To.
$to = get_option( 'admin_email' );
// Subject.
$subject = sprintf(
'Unsuccessful payment #%s notice',
$payment->get_id()
);
// Message.
$message = sprintf(
'A payment on %s has not been completed.',
get_bloginfo( 'name' )
);
$message .= str_repeat( PHP_EOL, 2 );
$message .= get_edit_post_link( $payment->get_id(), 'raw' );
// Send message.
wp_mail( $to, $subject, $message );
}
add_action( 'pronamic_payment_status_update', 'pronamic_pay_status_update_notice', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment