Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created June 15, 2017 17:51
Show Gist options
  • Save dancameron/2152f456f6375c2badd602494331eb78 to your computer and use it in GitHub Desktop.
Save dancameron/2152f456f6375c2badd602494331eb78 to your computer and use it in GitHub Desktop.
Automatically Send Invoice After Set to Pending
<?php // don't include this in your functions.php, since the start of the file should already have it
function maybe_send_invoice_notification( SI_Invoice $invoice, $status = '' ) {
if ( SI_Invoice::STATUS_PENDING === $status ) {
$client = $invoice->get_client();
if ( ! is_a( $client, 'SI_Client' ) ) {
return;
}
$recipients = $client->get_associated_users();
if ( empty( $recipients ) ) {
return;
}
do_action( 'send_invoice', $invoice, $recipients );
}
}
add_action( 'si_invoice_status_updated', 'maybe_send_invoice_notification', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment