Skip to content

Instantly share code, notes, and snippets.

@w33zy
Created April 7, 2023 12:03
Show Gist options
  • Save w33zy/7368f3049057793c3d7947cfb8c3d00f to your computer and use it in GitHub Desktop.
Save w33zy/7368f3049057793c3d7947cfb8c3d00f to your computer and use it in GitHub Desktop.
Auto-complete WooCommerce order based on payment gateway
<?php
function auto_complete_order( $order_id, $old_status, $new_status ) {
$order = wc_get_order( $order_id );
/*
* You can get the `your_payment_gateway` identifyer by visiting the WC payments setting page
* and selecting the gateway you would like to use. The payment gateway identifyer is the "section=" part of the browser URL
*/
if ( $new_status === 'processing' && $order->get_payment_method() === 'your_payment_gateway' ) {
$order->update_status( 'completed' );
}
}
add_action( 'woocommerce_order_status_changed', 'auto_complete_order', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment