Search here to get answers to your questions.

Available Action Hooks

ThankRedirect provides action hooks that let developers run custom code at specific points in the redirect flow. These hooks follow standard WordPress conventions and can be used in your theme’s functions.php file or in a custom plugin.

wpkin_before_thank_you_redirect

Fired immediately before ThankRedirect begins evaluating redirect rules for an order. This is the primary hook for developers who need to run custom logic before the redirect fires.

Usage

add_action( 'wpkin_before_thank_you_redirect', 'my_custom_pre_redirect_action', 10, 2 );

function my_custom_pre_redirect_action( $order, $settings ) {
    // $order    - WC_Order object for the completed order
    // $settings - array of all ThankRedirect settings
    
    // Your custom code here
}

Parameters

Parameter Type Description
$order WC_Order The WooCommerce order object for the completed order. Access any order data via WC_Order methods.
$settings array The full ThankRedirect settings array as saved in the database.

Example: Log Redirects to a Custom Table

add_action( 'wpkin_before_thank_you_redirect', 'log_thank_you_redirect', 10, 2 );

function log_thank_you_redirect( $order, $settings ) {
    $order_id    = $order->get_id();
    $customer    = $order->get_billing_email();
    $order_total = $order->get_total();
    
    // Log to a custom option or external service
    error_log( "ThankRedirect firing for order #{$order_id} ({$customer}) - Total: {$order_total}" );
}

Example: Skip Redirect for Specific Customer

add_action( 'wpkin_before_thank_you_redirect', 'skip_redirect_for_vip', 10, 2 );

function skip_redirect_for_vip( $order, $settings ) {
    $user_id = $order->get_user_id();
    if ( $user_id && user_can( $user_id, 'manage_options' ) ) {
        // Admins shouldn't be redirected - exit early via a custom flag or mechanism
    }
}

Standard WooCommerce Hook: woocommerce_thankyou

ThankRedirect hooks into WooCommerce’s own woocommerce_thankyou action at priority 1 (very early) to intercept the order before the default Thank You page renders. If you need to hook into this same action and run before ThankRedirect, use a priority lower than 1. To run after ThankRedirect, use priority 2 or higher.

// Run before ThankRedirect (priority 0)
add_action( 'woocommerce_thankyou', 'my_function_before_redirect', 0 );

// Run after ThankRedirect has processed (priority 5)
add_action( 'woocommerce_thankyou', 'my_function_after_redirect', 5 );
Note for developers: Because ThankRedirect redirects away from the WooCommerce Thank You page at priority 1, any hook running at priority 2+ on woocommerce_thankyou may not fire for redirected orders, as the page will have already sent a redirect header. Hook at priority 0 if you need to run before the redirect.
Last Updated: May 28, 2026