Add Dynamic Message in Thank You Page using Function | Web Development | CodePress Academy
Want to show a personalized Thank You message after a user completes a form or a purchase? A dynamic thank you message increases trust, improves UX and can even boost conversions. Isse user ko लगेगा कि आपने उनकी request notice की है — और engagement बढ़ेगा.
Watch the full 7-minute video
Why dynamic Thank You messages?
Static messages boring लगते हैं: "Thank you for your submission." लेकिन personalized message जैसे "Thank you, Rohit — we received your request." user को better experience देता है. Dynamic message से आप date, order number, coupon, या recommended content भी दिखा सकते हैं.
Use cases (जब आप dynamic message दिखाना चाहेंगे)
- Contact form submission → show sender name & next steps
- Checkout complete (WooCommerce) → show order number & ETA
- Signup confirmation → show username and welcome tips
- Download page → show personalized download link or expiry
Approach overview — कौन सा तरीका कब use करें
Different projects के लिए अलग तरीके best होते हैं:
- Simple PHP site: use query parameters and show message via PHP function.
- WordPress + Contact Form 7: redirect to thank you page with query string.
- WooCommerce: use woocommerce_thankyouhook to display order-specific messages.
- Advanced forms (Gravity Forms): use built-in confirmations or hooks to pass data.
Method 1 — Simple PHP + query string (fast & universal)
      If your form posts to process.php and then redirects to thankyou.php?name=Rohit, you can show the name on the page.
    
<?php
// thankyou.php
$name = isset($_GET['name']) ? htmlspecialchars($_GET['name']) : 'Guest';
$date = date('j M, Y');
echo "<h2>Thank you, {$name}!</h2>";
echo "<p>We received your request on {$date}.</p>";
?>
      Note: always use htmlspecialchars() to avoid XSS.  
      Ye method simple hai aur kisi bhi static PHP site par kaam karta hai.
    
Method 2 — WordPress + Contact Form 7 (CF7) redirect
Contact Form 7 se submit hone ke baad aap user ko thank you page par bhej sakte hain with query params. CF7 mein aap on_sent_ok (older) ya better use DOM event in JS to redirect. Example using JS:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
  var name = event.detail.inputs.find(i => i.name === 'your-name')?.value || 'Guest';
  window.location.href = '/thank-you/?name=' + encodeURIComponent(name);
}, false );
</script>
WordPress thank-you page पर आप वही PHP/JS logic चला कर personalized message दिखा सकते हैं.
Method 3 — WooCommerce: show dynamic message on Thank You page
      WooCommerce पर best approach hooks use करना है. Add this code in your child theme's functions.php or a snippets plugin:
    
// functions.php
add_action( 'woocommerce_thankyou', 'cp_custom_thankyou_message', 10, 1 );
function cp_custom_thankyou_message( $order_id ) {
    if ( ! $order_id ) return;
    $order = wc_get_order( $order_id );
    $name = $order->get_billing_first_name();
    $order_number = $order->get_order_number();
    echo '<div class="cp-thankyou">';
    echo '<h2>Thank you, ' . esc_html($name) . ' !</h2>';
    echo '<p>Your order # ' . esc_html($order_number) . ' has been received.</p>';
    echo '</div>';
}
This prints order-specific dynamic content — perfect for upsells, coupons, or delivery info.
Method 4 — Gravity Forms / Ninja Forms
      Advanced form plugins usually let you set a confirmation page and pass merge tags. Example: set confirmation to redirect to /thank-you/?name={Name:1}. On the thank you page use PHP/JS to read the name and show personalized text.
    
Security & best practices
- Always sanitize and escape user data (esc_html,htmlspecialchars).
- Avoid showing sensitive info (full email, passwords, payment details).
- Use HTTPS for all redirects and forms.
- Prefer server-side validation and only use query params for non-sensitive display.
- If using cookies or sessions, respect privacy and GDPR rules.
Bonus: Show a dynamic coupon or upsell
Example: after order success show a one-time coupon code:
// add in woocommerce_thankyou hook
$coupon = 'THANKS10'; // you can generate dynamic coupon via WC functions
echo '<p>Use code <strong>' . esc_html($coupon) . '</strong> for 10% off on your next order.</p>';
Testing tips (kaise test karein)
- Fill forms in incognito to avoid cached values.
- Test with special characters to ensure escaping works.
- Verify redirects and that query strings are encoded (use encodeURIComponentin JS).
- Check mobile responsiveness of the thank-you page.
FAQs
Q: Is it safe to pass user name in URL?
A: For non-sensitive display (first name) it's okay, but avoid passing emails, order totals, or private data in URL. Use sessions or server-side retrieval for sensitive info.
Q: Can I show different messages for different user types?
A: Yes — check user role (if logged in) or order meta and render accordingly. Example: offer different coupon to VIP customers.
Q: Where should I place custom code in WordPress?
A: Use a child theme's functions.php or a snippets plugin (like Code Snippets) so changes persist after theme updates.
Conclusion
Dynamic Thank You messages are a small change with big impact — personalized UX, higher trust, and more conversion opportunities. Use query params for simple sites, hooks for WooCommerce, and form plugin integrations for advanced forms. Always sanitize data, test thoroughly, and keep privacy in mind.
SEO Keywords: dynamic thank you message, WordPress thank you message function, WooCommerce thankyou hook, PHP thank you page, personalize thank you page.
Happy coding! Agar aap chahte hain toh main ye code aapke specific setup (theme/plugin) ke लिए customize करके दे दूँ — bataiye कौन सा platform use कर रहे हैं.

 
 
Hi Please Do not Spam in Comments