Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created July 21, 2015 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/435f6102b4cf2a72053f to your computer and use it in GitHub Desktop.
Save dancameron/435f6102b4cf2a72053f to your computer and use it in GitHub Desktop.
Redirect to Invoice After Estimate Approval
<?php // don't include this line since your functions.php file should already have this.
function si_redirect_after_estimate_approval() {
if ( 'estimate' !== si_get_doc_context() ) {
return;
}
?>
<script type="text/javascript">
jQuery(document).on('status_updated', function(e) {
window.location = window.location.pathname + '?redirect_after_status=1';
});
</script>
<?php
}
add_action( 'si_footer', 'si_redirect_after_estimate_approval' );
function si_maybe_redirect_after_estimate_approval() {
if ( 'estimate' !== si_get_doc_context() ) {
return;
}
if ( ! isset( $_GET['redirect_after_status'] ) && $_GET['redirect_after_status'] ) {
return;
}
$estimate = si_get_doc_object();
$status = $estimate->get_status();
// Check if approved
if ( SI_Estimate::STATUS_APPROVED !== $status ) {
return;
}
$invoice_id = $estimate->get_invoice_id();
if ( ! $invoice_id ) {
return;
}
wp_redirect( get_permalink( $invoice_id ) );
exit();
}
add_action( 'pre_si_estimate_view', 'si_maybe_redirect_after_estimate_approval' );
@seoproconsulting
Copy link

If we initially create an Estimate and send it then do we create an invoice to be lying in wait for the client to approve the estimate for this to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment