Created
April 7, 2023 12:03
-
-
Save w33zy/7368f3049057793c3d7947cfb8c3d00f to your computer and use it in GitHub Desktop.
Auto-complete WooCommerce order based on payment gateway
This file contains hidden or 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 | |
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