📣 Our next Live Stream Event is taking place on July 18, 2025

WooCommerce – Redirect User From Product Page If A Course Has Already Been Purchased

In this week’s blog post we want to highlight a custom function that was shared by a member of the WooCommerce development community that we have found particularly useful, and explain a use case for LearnDash which may be applicable to your own LMS & E-Commerce website.

Why You Might Wish To Redirect Users Who Have Already Purchased Your Course Product in WooCommerce

There are many different ways in which you may be selling access to courses on your website, such as with repeat subscriptions, timed memberships, linked or bulk course purchasing, and many other different business models that are available to online course sellers using both LearnDash and WooCommerce!

The most common method to sell courses in LearnDash using WooCommerce is to simply sell single seat user access using the free WooCommerce Integration addon available for LearnDash. This is the method of selling that this article is applicable to the most, as what we aim to achieve through this method is a way to prevent the user attempting to purchase or access a course page for a course which they already own.

You may instead want to redirect that user straight to the course homepage in LearnDash instead, if they have clicked onto the product page again by mistake intending to actually take the course that they have purchased. Another possibility is that you could redirect existing customers for the course product to another sales page where further addons and discounts for additional course bundles could be marketed.

Let’s now take a look at the function code itself.

The code

add_action( 'template_redirect', 'single_product_redirect_logged_in_purchased' );

function single_product_redirect_logged_in_purchased() { 
if ( ! is_product() && ! is_user_logged_in() ) return; 
$current_user = wp_get_current_user();
$product_id = get_queried_object_id();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id ) ) {
wp_safe_redirect( '/custom-url' );
exit;
}
}

This code snippet comes courtesy of Rodolfo Melogli at https://businessbloomer.com/bloomer-armada/. We highly endorse this blog for further code snippets for WooCommerce which you may find extremely useful.

Simply paste the code above into the functions.php file for your WordPress theme. You should also change the ‘/custom-rl’ text to be the redirect URL of choice, as this applies to all product IDs that have been purchased by the current user ID, we would recommend using a Learner Profile or Course Grid page where users can access the courses that they have purchased on your platform.

Customise your code further

If you wish to apply product page redirection per LearnDash course on your platform then this would certainly be achievable with further customisation of the code snippet above. Start by gathering the product IDs from your product pages in your WooCommerce site and then include a further IF Statement check prior to the wp_safe_redirect action that will check your specific product page ID against the one stored as the $product_id variable (collected at the moment the current user attempts to access the product page). If the statement is true then you can apply a specific URL redirect to that rule.

Schedule a meeting

Why not book a consultation call with us? We’re here to assist you with any questions or concerns you may have.

Please note: All bookings are subject to confirmation. We reserve the right to reschedule based on availability.