In WooCommerce development, we often need to perform certain actions after a user completes a payment, such as sending additional notification emails, updating member permissions, or synchronous data to external systems. Since WooCommerce supports various payment methods, understanding which Hooks are triggered upon payment completion is crucial for developers.
The woocommerce_payment_complete Hook
The most important Hook is woocommerce_payment_complete. This Hook is triggered after a payment has been successfully processed, regardless of the payment gateway used. It’s the ideal place to perform actions that depend on a successful payment.
add_action( 'woocommerce_payment_complete', 'wprs_payment_complete_action' );
function wprs_payment_complete_action( $order_id ){
$order = wc_get_order( $order_id );
// Post-payment logic here
}
Hooks Triggered by Order Status Changes
In addition to the main payment completion Hook, WooCommerce also triggers various order status change Hooks. For example, if an order moves from “Pending” to “Processing” or “Completed,” the corresponding Hook will be triggered.
Finally, woocommerce_payment_complete_order_status_$status will trigger for other specific order statuses.
add_action( 'woocommerce_payment_complete_order_status_processing', 'wprs_complete_for_status' );
add_action( 'woocommerce_payment_complete_order_status_completed', 'wprs_complete_for_status' );
function wprs_complete_for_status( $order_id ){
$order = wc_get_order( $order_id );
// Perform subsequent actions
}
One thing to note is that payment completion doesn’t always guarantee payment success in every scenario. In your hooked functions, you should still perform secondary checks on the order status. For higher-security operations, double-checking the payment amount with the payment gateway’s response is recommended to ensure the user has truly paid successfully before processing.
