Created
July 21, 2015 17:00
-
-
Save dancameron/435f6102b4cf2a72053f to your computer and use it in GitHub Desktop.
Redirect to Invoice After Estimate Approval
This file contains hidden or 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
<?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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?