Skip to content

Instantly share code, notes, and snippets.

@grantalltodavid
Created May 24, 2022 23:52
Show Gist options
  • Save grantalltodavid/75875e5a6cd0accdeaed77a163e60493 to your computer and use it in GitHub Desktop.
Save grantalltodavid/75875e5a6cd0accdeaed77a163e60493 to your computer and use it in GitHub Desktop.
Sliced Invoices: use same terms and conditions from Quote on the Invoice when converting a Quote to Invoice, or creating a new Invoice from an existing Quote
function si20220524_preserve_quote_terms_on_invoice_before( $id ) {
global $si20220524_quote_terms;
$si20220524_quote_terms = get_post_meta( $id, '_sliced_quote_terms', true );
}
function si20220524_preserve_quote_terms_on_invoice_after( $id, $new_post_id = null ) {
global $si20220524_quote_terms;
if ( $si20220524_quote_terms ) {
if ( $new_post_id ) {
// created new invoice from quote
update_post_meta( $new_post_id, '_sliced_invoice_terms', $si20220524_quote_terms );
} else {
// converted quote to invoice
update_post_meta( $id, '_sliced_invoice_terms', $si20220524_quote_terms );
}
$si20220524_quote_terms = null;
}
}
// for admin "convert quote to invoice" button:
add_action( 'sliced_invoices_admin_before_convert_quote_to_invoice', 'si20220524_preserve_quote_terms_on_invoice_before' );
add_action( 'sliced_invoices_admin_after_convert_quote_to_invoice', 'si20220524_preserve_quote_terms_on_invoice_after' );
// for admin "create new invoice from quote" button:
add_action( 'sliced_invoices_admin_before_create_invoice_from_quote', 'si20220524_preserve_quote_terms_on_invoice_before' );
add_action( 'sliced_invoices_admin_after_create_invoice_from_quote', 'si20220524_preserve_quote_terms_on_invoice_after', 10, 2 );
// for frontend "accept quote" button:
add_action( 'sliced_invoices_client_before_accept_quote', 'si20220524_preserve_quote_terms_on_invoice_before' );
add_action( 'sliced_client_accepted_quote', 'si20220524_preserve_quote_terms_on_invoice_after', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment