Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Created September 13, 2024 21:09
Show Gist options
  • Save coulterpeterson/e294ce78d99b428c4177e8b6aeb0aae4 to your computer and use it in GitHub Desktop.
Save coulterpeterson/e294ce78d99b428c4177e8b6aeb0aae4 to your computer and use it in GitHub Desktop.
WooCommerce Auto-Complete Order based on payment type
<?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