Created
June 23, 2021 16:19
-
-
Save vanbo/26ef8a2464b72e4b0b966ffb4067d9eb to your computer and use it in GitHub Desktop.
WC Paytrace - Set order to on hold when authorized only
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
/** | |
* IMPORTANT: Add the code to your "themes/theme-name/functions.php" file. | |
*/ | |
add_filter( 'woocommerce_payment_complete_order_status', 'vanbodevelops_set_order_to_onhold_after_processing', 10, 3 ); | |
function vanbodevelops_set_order_to_onhold_after_processing( $status, $order_id, $order_now ) { | |
$order = wc_get_order( $order_id ); | |
if ( ! class_exists( 'WC_Paytrace_Order' ) ) { | |
return $status; | |
} | |
// It's our gateway | |
if ( 'paytrace' != $order->get_payment_method() ) { | |
return $status; | |
} | |
$pt_order = new WC_Paytrace_Order( $order ); | |
// A card is used | |
if ( 'card' != $pt_order->get_payment_type() ) { | |
return $status; | |
} | |
/** | |
* The payment is not captured yet | |
*/ | |
if ( $pt_order->get_is_payment_captured() ) { | |
return $status; | |
} | |
// Make sure that we are using the checkout | |
if ( ! isset( $_POST['payment_method'] ) && 'paytrace' == $_POST['payment_method'] ) { | |
return $status; | |
} | |
return 'on-hold'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment