Created
August 13, 2019 15:14
-
-
Save dancameron/b6736828c3d29179f9de5743eef07ace to your computer and use it in GitHub Desktop.
Change Status of Invoice after WooCommerce Payment Status Update
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
<?php // don't include this line in your functions.php, since it already starts with it. | |
// remove action within SI add-on | |
remove_action( 'si_invoice_status_updated', array( 'Woo_Payments_Integration', 'maybe_change_order_status' ), 10, 2 ); | |
// recreate action with processing status | |
function maybe_change_order_status( SI_Invoice $invoice, $status = '' ) { | |
$order_id = get_post_meta( $invoice->get_id(), self::ORDER_ID_META, true ); | |
if ( ! $order_id ) { | |
return; | |
} | |
$order = wc_get_order( $order_id ); | |
switch ( $status ) { | |
case SI_Invoice::STATUS_PAID: | |
$order->update_status( 'processing', __( 'Invoice payment complete', 'sprout-invoices' ) ); | |
break; | |
case SI_Invoice::STATUS_WO: | |
$order->update_status( 'cancelled', __( 'Invoice written-off', 'sprout-invoices' ) ); | |
break; | |
default: | |
break; | |
} | |
} | |
add_action( 'si_invoice_status_updated', '_maybe_change_order_status', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is a customization for Sprout Invoices. A customizable solution that provides a way for you to get paid via your WordPress site. For more information please don't hesitate to reach out.