Created
November 7, 2017 04:11
-
-
Save grantalltodavid/567926710789c500f04b48d6573867cc to your computer and use it in GitHub Desktop.
Sliced Invoices: automatically send invoice to client upon invoice creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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