Search here to get answers to your questions.

Adding Custom URL Placeholders

ThankRedirect Pro’s URL Personalisation feature ships with a set of built-in placeholders like [billing_first_name] and [order_total]. Using the wpkin_thankyou_url_placeholders filter, developers can add their own custom placeholders, pulling any data from the order, the customer, or anywhere else in WordPress.

How Placeholders Work

When ThankRedirect builds a redirect URL, it scans the URL for placeholder tags and replaces each one with its corresponding value from the order. Built-in placeholders handle the most common data points. Custom placeholders let you extend this with anything your store tracks.

Adding a Custom Placeholder

Add your code to your theme’s functions.php or a custom plugin:

add_filter( 'wpkin_thankyou_url_placeholders', 'add_my_custom_placeholders', 10, 2 );

function add_my_custom_placeholders( $placeholders, $order ) {
    // Add a custom order meta field as a placeholder
    $placeholders['[order_ref]'] = $order->get_meta( '_custom_order_reference' );
    
    return $placeholders;
}

Now you can use [order_ref] in your redirect URL in ThankRedirect’s settings, and it will be replaced with the value of _custom_order_reference from each order.

Practical Examples

Example 1: Custom Order Reference Number

Your store uses a custom order reference field (e.g., from a CRM integration). Expose it as a URL placeholder:

$placeholders['[crm_ref]'] = $order->get_meta( '_crm_reference_id' );

Use in redirect URL: https://crm.yourstore.com/orders?ref=[crm_ref]

Example 2: Order Item Count

$placeholders['[item_count]'] = $order->get_item_count();

Use in redirect URL: https://yourstore.com/thank-you?items=[item_count]

Example 3: Customer’s City

$placeholders['[billing_city]'] = $order->get_billing_city();

Example 4: Multiple Placeholders at Once

add_filter( 'wpkin_thankyou_url_placeholders', 'add_store_placeholders', 10, 2 );

function add_store_placeholders( $placeholders, $order ) {
    $placeholders['[billing_city]']    = $order->get_billing_city();
    $placeholders['[billing_country]'] = $order->get_billing_country();
    $placeholders['[item_count]']      = $order->get_item_count();
    $placeholders['[customer_id]']     = $order->get_user_id();
    
    return $placeholders;
}

Placeholder Naming Convention

  • Wrap your placeholder key in square brackets: [placeholder_name]
  • Use lowercase letters and underscores only
  • Avoid using the same name as a built-in placeholder (see the full list in URL Personalisation)

Sanitising Output

ThankRedirect URL-encodes placeholder values when it inserts them into the URL. However, you should still sanitise the data you pass as placeholder values to avoid unexpected characters:

$placeholders['[custom_field]'] = sanitize_text_field( $order->get_meta( '_my_field' ) );
Pro tip: Custom placeholders are a powerful bridge between ThankRedirect and external tools. For example, pass a customer’s loyalty tier (stored in user meta) as a placeholder and use it to redirect different customers to different onboarding flows on an external platform, all without any server-side logic on the destination.
Last Updated: May 28, 2026