Created
September 13, 2024 21:09
-
-
Save coulterpeterson/e294ce78d99b428c4177e8b6aeb0aae4 to your computer and use it in GitHub Desktop.
WooCommerce Auto-Complete Order based on payment type
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 | |
// Complete order if it was a credit card order or other instant payment type | |
add_action( 'woocommerce_payment_complete', function ( $order_id ) { | |
$order = new WC_Order( $order_id ); | |
//$payment_type = $order->get_payment_method_title(); | |
// 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', '' ) ) ) { | |
// Credit: https://stackoverflow.com/a/35689563 | |
return; | |
} | |
$order->update_status( 'completed' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment