Skip to content

Instantly share code, notes, and snippets.

@grantalltodavid
Created November 7, 2017 04:11
Show Gist options
  • Save grantalltodavid/567926710789c500f04b48d6573867cc to your computer and use it in GitHub Desktop.
Save grantalltodavid/567926710789c500f04b48d6573867cc to your computer and use it in GitHub Desktop.
Sliced Invoices: automatically send invoice to client upon invoice creation
add_action( 'new_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'draft_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'pending_to_publish', 'sliced_auto_send_invoice', 10, 1 );
add_action( 'sliced_auto_send_invoice_deferred', 'sliced_auto_send_invoice_deferred_function', 10, 1 );
function sliced_auto_send_invoice( $post ) {
if ( $post->post_type === 'sliced_invoice' ) {
// run in background
wp_schedule_single_event( time(), 'sliced_auto_send_invoice_deferred', array( $post ) );
}
}
function sliced_auto_send_invoice_deferred_function( $post ) {
if ( $post->post_type === 'sliced_invoice' ) {
$sliced_notifications = new Sliced_Notifications();
$sliced_notifications->send_the_invoice( $post->ID );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment