If you have your LearnDash course for sale with WooCommerce. You can send the users to predefined page to increase user experience. In the below example, we will redirect users to the My Account page.
Getting Started #
Our documentation will require PHP and/or JavaScript code. To use the code you must place it in your WordPress code in an appropriate place to load, usually in a theme or plugin.
PHP #
PHP code can be placed in your theme’s functions.php file, or in a standalone plugin if you know how to make one.
JavaScript #
JavaScript code should be placed in a JavaScript file (.js) and enqueued using wp_enqueue_scripts. There are other ways of getting JavaScript on the page, but this is the most recommended to avoid future problems with JavaScript code on the page.
Example #
add_action( 'template_redirect', 'ea_custom_redirect_after_purchase' );
function ea_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
// Change the URL below to the URL you want your customer to be redirected to.
wp_redirect( get_site_url() . '/my-account' );
exit;
}
}
The callback function, ea_custom_redirect_after_purchase should return a URL (string) of where to send the user.