What is the action hook for an order that fails on frontend checkout in WooCommerce?

I am working on a plugin that handles logic for when a user tries to checkout on the frontend and the order fails (e.g., person is using a credit card but it does not have enough balance to meet the cart totals, etc). I can see the order is in fact set as “FAILED” in WooCommerce, because I get the automated email from WC alerting admin of a failed order. I’m spending a lot of time testing out various actions and filters, and hoping someone could point me in the right direction.

2 Answers
2

You can catch specific status change by using this action hook ‘woocommerce_order_status_{status}’. It is defined in the WC_Order class.

This is how you define it:

/**
 * Executed when the status is changed to failed.
 * @param int $order_id
 * @param \WC_Order $order
 */
function wpdg_9291_woocommerce_order_status_failed( $order_id, $order ) {
    // Do something here
}
add_action('woocommerce_order_status_failed', 'wpdg_9291_woocommerce_order_status_failed', 15, 2);

Leave a Comment