To set a LearnDash redirect after purchase, you have two options. Without code, fill in the course's Course Enrollment URL field (or the gateway's Return URL) with your thank-you page. With code, hook the learndash_payment_option_url_success filter, which receives the URL LearnDash picked, the gateway name and the purchased products, and lets you return any page you like, per course or for the whole site.
This snippet guide explains the order LearnDash uses to choose the success URL, gives a filter you can drop into a site plugin, and lists the details that catch people out with Stripe, PayPal, Razorpay and 100% coupons. Checked against the LearnDash 4.18.0.1 source code. LearnDash 5.x is current (5.2.3 as of late October 2026, per the official changelog); the filter was added in 4.5.0, so confirm it on your own version before you rely on it.
How LearnDash picks the page after a purchase
All built-in gateways call one method, Learndash_Payment_Gateway::get_url_success(), to decide where the buyer lands. It walks through four sources and uses the first one that is set:
- The product's own enrollment URL. When exactly one course or group is bought, LearnDash reads its Enrollment URL setting. Buy now and Recurring products each have their own field.
- The gateway's return URL. The Return URL field in the Stripe Connect, PayPal or Razorpay settings under LearnDash LMS > Settings > Payments.
- The Registration Success page. The page chosen under LearnDash LMS > Settings > Registration/Login.
- The course or group permalink, and failing that, the home page.
Whichever URL wins is passed through learndash_payment_option_url_success before it is used. That is why the filter is the reliable place for custom logic: it sees the final choice, whatever the settings say.
The no-code route: settings
| Setting | Where | Scope |
|---|---|---|
| Course Enrollment URL | Course > Settings, under the Buy now or Recurring access mode | That course only |
| Group Enrollment URL | Group > Settings, same access modes | That group only |
| Return URL | LearnDash LMS > Settings > Payments, in each gateway's section | Every purchase through that gateway |
| Registration Success | LearnDash LMS > Settings > Registration/Login | Sitewide fallback |
If one thank-you page for everything is enough, set the gateway Return URL and stop there. Reach for code when the page depends on the product, the gateway or the buyer.
The snippet: a thank-you page per course
This filter maps course or group IDs to thank-you page IDs, falls back to a sitewide page, and leaves any URL an editor set on the product itself alone. Put it in a small site plugin or your child theme's functions.php and replace the IDs. Not run on a live site; test on staging first.
<?php
/**
* Send LearnDash buyers to a thank-you page after a successful payment.
*
* @param string $url URL LearnDash chose.
* @param string $gateway_name Gateway name, for example 'stripe_connect'.
* @param array $products Purchased LearnDash\Core\Models\Product objects.
* @return string
*/
function aiol_ld_thank_you_url( $url, $gateway_name, $products ) {
// Course or group ID => thank-you page ID.
$map = array(
123 => 456,
124 => 457,
);
$default_page = 458; // Sitewide thank-you page. Use 0 to keep LearnDash's choice.
if ( ! is_array( $products ) || 1 !== count( $products ) ) {
return $url;
}
$product = reset( $products );
if ( ! $product instanceof \LearnDash\Core\Models\Product ) {
return $url;
}
$product_id = (int) $product->get_id();
// Respect an Enrollment URL set on the course or group itself.
if ( untrailingslashit( $url ) !== untrailingslashit( (string) get_permalink( $product_id ) )
&& untrailingslashit( $url ) !== untrailingslashit( home_url() )
&& ! isset( $map[ $product_id ] ) ) {
return $url;
}
$page_id = isset( $map[ $product_id ] ) ? (int) $map[ $product_id ] : (int) $default_page;
$page_url = $page_id ? get_permalink( $page_id ) : '';
if ( ! $page_url ) {
return $url;
}
return add_query_arg( 'ld_product', $product_id, $page_url );
}
add_filter( 'learndash_payment_option_url_success', 'aiol_ld_thank_you_url', 10, 3 );
The ld_product argument lets the thank-you page show the right course name and a "Start the course" link. Treat it as a hint only: read it with absint(), escape anything you print, and never use it to grant access, because anyone can type it into the address bar.
Gateway details that change the result
- Stripe Connect appends
ld_stripe_connect=successand asession_idto whatever URL you return, after the filter runs. LearnDash also prints a "Your transaction was successful." alert inwp_footeron any page that carries that argument, so the alert appears on your thank-you page too. Design the page with that in mind. - Stripe and enrolment timing. With Stripe, access is granted when the webhook is processed, not when the buyer returns. On a slow webhook the buyer can reach the thank-you page a moment before enrolment exists, so link to the course rather than embedding content that needs access.
- PayPal (IPN) grants access in its return handler and then redirects through the same method, with
paypal_ipnas the gateway name. Its Cancel URL uses the separatelearndash_payment_option_url_failfilter. - Razorpay passes the URL back to its checkout script, which redirects in the browser. The gateway name is
razorpay. - 100% coupons. When a coupon brings the price to zero, LearnDash enrols the user directly and calls the same method with an empty gateway name. If you filter by
$gateway_name, decide what an empty string should do.
When the filter does not apply
Purchases made through WooCommerce with the LearnDash WooCommerce add-on never touch this filter: WooCommerce owns checkout and its order-received page. The same goes for membership plugins that sell access themselves. Change the redirect in that plugin instead. The filter also does not run for Open or Free courses, because nothing is paid; for those, look at the join and access redirects covered in our post on the LearnDash redirect for users without access.
Test it properly
- Put Stripe or PayPal in test mode and buy as a fresh subscriber in a private window, not as an admin.
- Check the URL you land on and the query arguments on it.
- Confirm the course appears in the user's profile after the webhook arrives.
- Repeat with a 100% coupon and with a group, if you sell groups.
If you are also renaming the purchase button, our snippet to change the LearnDash buy button text pairs well with this one, and the LearnDash guide covers access modes and pricing settings in more depth.
How we can help
If your post-purchase flow needs more than a redirect, such as onboarding emails, CRM tagging or a custom checkout, our LMS plugin development team builds it as a maintainable plugin. You can also tell us what you need. LearnDash is a trademark of its owner; All-in-One LMS is an independent development company and is not affiliated with LearnDash.
Frequently asked questions
How do I redirect to a thank-you page after a LearnDash purchase?
Set the Course Enrollment URL in the course's Buy now or Recurring settings for one course, or the Return URL in your gateway's section under LearnDash LMS > Settings > Payments for every purchase. For per-product or conditional logic, use the learndash_payment_option_url_success filter.
Why does my LearnDash thank-you page show a 'transaction was successful' alert?
With Stripe Connect, LearnDash adds ld_stripe_connect=success to the return URL and prints that alert in the footer of any page that carries it. It appears on whatever page you redirect to.
Does the LearnDash success URL filter work with WooCommerce?
No. When courses are sold through WooCommerce with the LearnDash WooCommerce add-on, WooCommerce handles checkout and its order-received page, so the redirect has to be changed on the WooCommerce side.
Where do buyers go if a LearnDash payment is cancelled?
To the PayPal Cancel URL if one is set, otherwise to the course or group page. You can change it with the learndash_payment_option_url_fail filter, which takes the same three arguments.
Free 30-minute consultation
Not sure where to start? Talk to an LMS engineer.
Tell us what platform you run and what you need. You’ll get honest, practical advice - even if the answer is that you don’t need us.
Sources & references
- LearnDash LMS changelog - LearnDash documentation (Nexcess)
- add_query_arg() - WordPress.org
- get_permalink() - WordPress.org
- Plugin API: Filters - WordPress.org
Learn more about this topic with AI
Gemini opens with the prompt copied - paste it into the chat to start.