Skip to content

Instantly share code, notes, and snippets.

@grantalltodavid
Last active June 22, 2020 20:37
Show Gist options
  • Save grantalltodavid/ef2ecef341e8caff8de6adba1012547d to your computer and use it in GitHub Desktop.
Save grantalltodavid/ef2ecef341e8caff8de6adba1012547d to your computer and use it in GitHub Desktop.
Sliced Invoices: automatically send quote to client upon invoice creation
add_action( 'new_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'draft_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'pending_to_publish', 'sliced_auto_send_quote', 10, 1 );
add_action( 'sliced_auto_send_quote_deferred', 'sliced_auto_send_quote_deferred_function', 10, 1 );
function sliced_auto_send_quote( $post ) {
if ( $post->post_type === 'sliced_quote' ) {
// run in background
wp_schedule_single_event( time(), 'sliced_auto_send_quote_deferred', array( $post ) );
}
}
function sliced_auto_send_quote_deferred_function( $post ) {
if ( $post->post_type === 'sliced_quote' ) {
$sliced_notifications = Sliced_Notifications::get_instance();
$sliced_notifications->send_the_quote( $post->ID );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment