Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Last active October 30, 2018 14:39
Show Gist options
  • Save nfsarmento/a1cd66e3c36e55736d1c50681610530d to your computer and use it in GitHub Desktop.
Save nfsarmento/a1cd66e3c36e55736d1c50681610530d to your computer and use it in GitHub Desktop.
WooCommerce: Auto complete paid Orders depending on payment methods
/** WooCommerce: Auto complete paid Orders depending on payment methods
*
* https://www.nuno-sarmento.com
*/
add_action( 'woocommerce_thankyou', 'ns_wc_auto_complete_paid_order', 20, 1 );
function ns_wc_auto_complete_paid_order( $order_id ) {
if ( ! $order_id )
return;
// Get an instance of the WC_Product object
$order = wc_get_order( $order_id );
// No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( in_array( $order->get_payment_method(), array( 'bacs', 'cod', 'cheque', '' ) ) ) {
return;
// Updated status to "completed" for paid Orders with all others payment methods
} else {
$order->update_status( 'completed' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment