Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created August 13, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/b6736828c3d29179f9de5743eef07ace to your computer and use it in GitHub Desktop.
Save dancameron/b6736828c3d29179f9de5743eef07ace to your computer and use it in GitHub Desktop.
Change Status of Invoice after WooCommerce Payment Status Update
<?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 );
@dancameron
Copy link
Author

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.

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