Title: Woocommerce hook after a successful payment
Tags: wordpress;woocommerce;hook-woocommerce
Question: I'm using emerchantpay for the payment gateway. Sometimes it does not redirect after the successful payment and it only happened during production. I wanted to create a fallback if that happens by using a hook which I found woocommerce_payment_complete and/or woocommerce_order_status_changed.
I've added it on my main controller to where all my hook is.
public function init()
add_action('woocommerce_order_status_changed', [$this, 'status_changed', 10, 3]);
add_action('woocommerce_payment_complete', [$this, 'woocommerce_payment_complete']);
public function status_changed( $id, $previous_status, $next_status )
$order = new WC_Order($id);
$order-&gt;update_status( 'completed' );
var_dump('COMPLETE', $order);
error_log('status_changed');
exit;
public function woocommerce_payment_complete( $order_id )
$order = wc_get_order( $order_id );
$order-&gt;update_status( 'completed' );
var_dump('COMPLETE', $order);
error_log('woocommerce_payment_complete');
exit;
I've added a dump on each method and an error log to check if the actions were actually called but none of them were called.
Is there any way that I could trigger the hook or is there another hook that I can use to do this?
Thanks in advance!


Here is another answer: You can use woocommerce_payment_complete_order_status hook for the same
add_filter( 'woocommerce_payment_complete_order_status', 'completed_orders', 9999 );
function completed_orders() {
return 'test';

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:07/22/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<wordpress><woocommerce><hook-woocommerce>', 'Title': 'Woocommerce hook after a successful payment', 'ViewCount': 44, 'id': 73078587, 'user_AboutMe': '<p>I love to eat</p>\n', 'user_AccountId': 2114299.0, 'user_DisplayName': 'the_lorem_ipsum_guy', 'user_Reputation': 432.0, 'user_Views': 68.0, 'user_id': 1878924.0}}