• Skip to primary navigation
  • Skip to main content

Thomas Le Coz

I'm a Hacker

  • About

Making WooCommerce Subscriptions and Learndash compatible

Last updated: August 7, 2020

WooCommerce Subscriptions and LearnDash

Update: thanks to many of you and your remarks I’ve updated my code to make it compatible with the new LearnDash and solve several other problems. To keep it easy to understand, I’ve left this article untouched and added the updated code in the “Code Update” section you can access at the end of the article (or just click here).

I love LearnDash and I love WooCommerce. They are my go-to platforms for respectively LMS and e-commerce. I do use different programs in specific cases but by default, I use them.

Recently, a client asked for a drip-fed course sold by installments throughout the drip-feeding. The client would get a bill each time a lesson would go live.

I did my research and I found no viable option for paying by installments in a clean way.  I wanted to keep the backend easy to manage and enjoy the power of WooCommerce.

I saw screenshots of WooCommerce Subscriptions and thought it was the perfect solution.

WooCommerce Subscriptions preview

I bought it and started to configure everything. It looked freakin’ good but wasn’t really working for my purpose. So I had to take some time to make a custom solution and I thought I would share it here.

This will be a two-part article series. The first part will be dedicated to making WooCommerce Subscriptions and LearnDash compatible. The second part will talk about modifying the plugin to allow installment payments.

Warning: this article will be more technical than the rest of the blog.

Prerequisites

So, what do you need?

  • a WordPress
  • WooCommerce plugin
  • LearnDash plugin
  • LearnDash WooCommerce Add-on
  • WooCommerce Subscriptions

Once you’ve got everything installed in a dev environment, we’ll dive into the code. 

Selling a course through a subscription

Before hacking the source code, there is a simple manipulation to sell your courses in a subscription. You won’t be able to do anything else than giving access to the course, though.

Here are the steps:

  1. Create a new WooCommerce product
  2. Select “Course” in product type
  3. Select the course(s) you want to sell
  4. Save the draft
  5. Change the product type to subscription
  6. Configure the subscription
  7. Hit publish

What happens is, switching to a subscription doesn’t remove the associated courses. But again, if you’re selling this to a client, it’s not elegant so let’s code something to fix this shall we?

Note: all the code will be done directly on the LearnDash WooCommerce extension. After discussing the matter on their support forums, it seemed like the cleanest option.

Note 2: I’m not an extremely efficient coder, if you think my code can be optimized, comment below so we can improve it :)

We want to go from this:

WC Subs not showing LD Courses

To this:

WC Subs showing LD courses

And it’s fairly easy when you look at the source code. It’s handled by CSS rules. You can trick them by adding “show_if_simple” in the render_course_selector() function.

Giving and removing access to courses when the subscription state changes

So now, we can sell courses on a subscription basis. But if someone cancels or puts on hold the payments, he still has access to the course. And this sucks because you get robbed. So how to fix this?

WooCommerce Subscription has some nice action hooks to take care of this. Let’s head over to the LearnDash WooCommerce constructor to take care of the following:

  • on hold
  • suspended
  • expired: this one triggers when the membership expires if there’s a limit to it. Keep this in mind for the next article ;)

Now let’s create two functions to give or remove access. Both functions will be similar. The first part is to find the courses corresponding to the subscription. The second gives or removes access to the course.

Code Update

The code above is very useful to understand what I did to get WooCommerce Subscriptions and LearnDash working together, but there was a couple of problems (even without WooSubs and LearnDash both updating their code):

  • if you were drip-feeding your course, it would reset the subscription date to the course every time the subscription would be billed. So for a weekly course with a weekly subscription, your subscribers wouldn’t go past the first week (but still get billed each week) which was a big issue for me and my client and my client’s clients
  • the code was sometimes putting duplicates in the access list which is not really clean

The new code below solves all of this.

Warning: I’m more a technical marketer than a developer. What I do work but is probably not the most efficient way to do so. Some parts are just a repeat of the course access management function provided in the LearnDash source code. If you have ideas or improvements in mind, feel free to use the comments, happy to update :)

The New send_receipt() function

Each time a transaction go through, send_receipt() is triggered and updates the course access list and the date the subscriber gained accessed to the course, so I needed to modify this.

The new give_course_access() function

Same thing, I basically check the access list before giving access to the course, in order to keep the date the subscriber accessed the course the same and avoid resetting its access (and messing with the drip-fed access).

That’s all folks

Yep, it’s done. So of course, we can add options to make it easier to customize, but this should get you started.

The next article will be about customizing WooCommerce Subscription to sell by installments.

If you have comments specific to the code or if you have questions feel free to hit me up in the comments below :)

Filed Under: Blog, Tech

Reader Interactions

Comments

  1. Justin Ferriman says

    February 19, 2015 at 3:18 pm

    Fantastic post Thomas, a great resource for LearnDash and WooCommerce users – really provides a nifty way to sell course content. Keep up the great articles!

    • ThomasLeCoz says

      February 19, 2015 at 4:40 pm

      Glad you like it! Pleased to see you on this brand new site :)

      Keep up the good work at LearnDash LMS!

  2. Cedric Paulin Halenria says

    March 1, 2015 at 12:52 am

    Hello, as the subscription plugin is expensive, do you think your solution could work with http://codecanyon.net/item/subscriptio-woocommerce-subscriptions/8754068 ?

    I already bought this one, going to try your solution, but if I failed, I’m not sure to know if the cause will be the plugin or the guy behind the keyboard…

    cEd

    • ThomasLeCoz says

      March 1, 2015 at 11:25 am

      Hey cEd,

      Short answer: my code won’t work with your plugin.

      Long answer: the code here is tailored to WooThemes’ hooks. I couldn’t find the specific action hooks for Subscriptio on RightPress’ site but found some info on their WooCommerce Membership plugin.

      http://support.rightpress.net/hc/en-us/articles/201768115-Developers-Action-Filter-Reference

      This is the kind of stuff you need (if it’s implemented in their code). You can look for the do_action(); pieces of code in their source code. See if there’s a way to tie everything together (or look for that hidden API documentation I wasn’t able to find).

      Hope this helps ;)

    • ThomasLeCoz says

      March 2, 2015 at 3:23 pm

      Just thought about this while working on another project.

      I was forced to use WooCommerce Subscriptions as I wanted to be able to offer two different payment plans for one product and sell by installments (see: http://thomaslecoz.com/sell-by-installments-with-woocommerce-subscriptions/ )

      However, a quick way to sell memberships or subscriptions in your case might be using WooCommerce and Paid Membership Pro with the WooCommerce add-on.

      You can then sell memberships through your WooCommerce.

      Does this help?

      • Cedric Paulin Halenria says

        March 2, 2015 at 5:14 pm

        I’m just leaving the solution to use PMPro with WPCourseware because I want to propose several programs and PMPro is great when there is only one program/membership to sell. In this case, it’s indeed an excellent solution.

  3. Cedric Paulin Halenria says

    April 12, 2015 at 3:08 pm

    So, I bought WC Subscriptions to use your solution :)
    But I have a question… where to put the code you gave ? New files ? existing files to be modified ?

    Best regards
    Cedric

    • ThomasLeCoz says

      April 12, 2015 at 7:55 pm

      Hey man :)

      So most of the code takes place in the LearnDash add-on for WooCommerce. I’ll try to edit the article later this week to make it clearer there is no fresh code / plugin / files to create.

      You only need to modify the existing code. As it’s not in the WordPress repository, you won’t have auto-update that will replace your customizations, just be careful when you manually update.

      The file is in your wp-content/plugins/learndash_woocommerce directory and is called learndash_woocommerce.php

      The two functions give_course_access and remove_course_access can be added at the end of this file (before the closing brackets, before new learndash_woocommerce(); ) and the add_actions modification takes place in the constructor (the first function you’ll find).

      Hope this helps ;)

  4. Ted says

    April 20, 2015 at 8:59 pm

    Appreciate the tutorial. Very well explained and helpful. You saved me a lot of time.

    • ThomasLeCoz says

      April 21, 2015 at 8:53 am

      Glad I could help ;)

  5. Ted says

    May 25, 2015 at 12:44 pm

    Everything works great. I set out to try using the action ‘subscription_end_of_prepaid_term’ instead of ‘cancelled_subscription’, to allow users to have access till their prepaid period end to then block the access. But after the prepaid term ends, I can still access the course. It is as if the code won’t update when this happens. Am I missing something?

    • ThomasLeCoz says

      May 25, 2015 at 1:12 pm

      Hi Ted,

      If it works in other cases, this mean that subscription_end_of_prepaid_term isn’t triggered or doesn’t give the right user ID or subscription key… I would enable logs in WP-Config and put logs everywhere through the workflow of the user to try to see what’s triggered and when… Maybe when a prepaid period expire the sub key changes?

      Also, note that you can see who has access on a given closed course at any time by checking the list of IDs in the “Course” tab. When remove_course_access() is triggered, it deletes the ID from this list.

      Please keep me posted on your progress on this issue :)

      • Ted says

        May 25, 2015 at 1:55 pm

        thanks for your quick reply. I will be looking into it later tonight, but I quickly checked the list of IDs and already see that it adds 2x the same ID number. Wonder if this might be the issue, where only one gets removed in the end of the subscription. I will keep you posted

        • ThomasLeCoz says

          May 25, 2015 at 1:57 pm

          From memory my code deletes all the IDs at once (I had double IDs too).

  6. Cedric Paulin Halenria says

    June 12, 2015 at 11:31 am

    Well I had the opportunity to test your solution and it’s great. Thanks for this.
    One question (or maybe two ? )
    – I offer a warranty to my customers : satisfied or refunded. Is there a trigger to cut the access when I refund ?
    – Is there a way to do the same for customers who pay in one payment ? (For the case satisfied or refunded ?)

    Cedric

    • ThomasLeCoz says

      June 12, 2015 at 1:11 pm

      Hi Cedric,

      I would have a look at what’s triggered in both cases then just add the hook where I put all my add_action() functions.

      add_action(‘HOOK_WHEN_REFUND’, array($this, ‘remove_course_access’), 10, 2);

      I would try with “woocommerce_order_status_refund” but browse the doc to be sure. This would look like this :

      add_action(‘woocommerce_order_status_refund’, array($this, ‘remove_course_access’), 10, 2);

      Hope this helps!

  7. MJ says

    August 12, 2015 at 4:46 pm

    Thank you so much for offering this fix! I was so excited to try it as everything was working fine for me except that my students weren’t being removed from the courses after cancellation/expiration. Unfortunately, it doesn’t seem to be working. My students are still not getting removed. I am running LD 2.0.6.6, WC 2.3.13, WP 4.2.4, and LD WC Integration 1.2. I do have the WC auto-complete code in my functions.php. I would greatly greatly appreciate it if you could help me get this working. Thank you so much!

    • ThomasLeCoz says

      August 12, 2015 at 5:29 pm

      Hey MJ,

      Glad you liked the article! This is weird, they should get removed with the hook:

      add_action(‘subscription_expired’, array($this, ‘remove_course_access’), 10, 2);

      (in the constructor of the LD WC Integration). However (I’ll probably update this article or create a new one) note that there is a new WooThemes plugin that will allow you to make payment plans more easily I think.

      Haven’t tested this yet, probably still need to make LearnDash compatible with it. You can have a look here: http://www.woothemes.com/products/woocommerce-deposits/

      Hope this helps, let me know if the hook is in the LD WC integration and it still doesn’t work.

      • MJ says

        August 12, 2015 at 10:10 pm

        Hi Thomas,

        Thank you so much for your reply!

        This is what my learndash_woocommerce.php code looks like:

        /* Plugin Name: LearnDash WooCommerce Integration Plugin URI: http://www.learndash.com Description: LearnDash WooCommerce Integration Plugin Version: 1.2 Author: LearnDash Author URI: http://www.learndash.com */ class learndash_woocommerce { public $debug = true; function __construct() { add_filter('product_type_selector', array($this, 'add_product_type'), 1, 2); add_action('woocommerce_product_options_general_product_data', array($this, 'render_course_selector')); add_action('admin_enqueue_scripts', array($this, 'add_scripts')); add_action( 'wp_enqueue_scripts', array( $this, 'add_front_scripts' ) ); add_action('save_post', array($this, 'store_related_courses'), 1, 2); add_action('woocommerce_order_status_completed', array($this, 'send_receipt'), 10, 1); add_action('woocommerce_order_status_processing', array($this, 'send_receipt'), 10, 1); add_action('cancelled_subscription', array($this, 'remove_course_access'), 10, 2); add_action('subscription_put_on-hold', array($this, 'remove_course_access'), 10, 2); add_action('subscription_expired', array($this, 'remove_course_access'), 10, 2); add_action('activated_subscription', array($this, 'give_course_access'), 10, 2); } function add_product_type($types, $product_type) { $types['course'] = __( 'Course', 'learndash'); return $types; } function add_scripts(){ wp_enqueue_script( 'ld_wc', plugins_url('/learndash_woocommerce.js', __FILE__), array('jquery') ); } function add_front_scripts(){ wp_enqueue_script( 'ld_wc_front', plugins_url('/front.js', __FILE__), array('jquery') ); } function render_course_selector() { global $post; $courses = $this->list_courses(); echo ''; $values = get_post_meta($post->ID, '_related_course', true); if(!$values) $values = array(); woocommerce_wp_select(array( 'id' => '_related_course[]', 'label' => __('Related Courses', 'learndash'), 'options' => $courses, 'desc_tip' => true, 'description' => __('You can select multiple courses to sell together holding the SHIFT key when clicking.', 'learndash') )); echo 'ldRelatedCourses = ' . json_encode($values) . ''; echo ''; } function store_related_courses($id, $post){ $related_courses = $_POST['_related_course']; if(isset($_POST['_related_course'])) update_post_meta($id, '_related_course', $_POST['_related_course']); } function send_receipt($order_id){ //if($new_status == 'processing' && $status != 'completed' || $new_status == 'completed' && $status == 'processing'){ if($status != 'processing' && $status != 'completed') { $order = new WC_Order($order_id); $products = $order->get_items(); foreach($products as $product){ $courses_id = get_post_meta($product['product_id'], '_related_course', true); if($courses_id && is_array($courses_id)){ foreach($courses_id as $cid) ld_update_course_access($order->customer_user, $cid); } } } } function debug($msg) { $original_log_errors = ini_get('log_errors'); $original_error_log = ini_get('error_log'); ini_set('log_errors', true); ini_set('error_log', dirname(__FILE__).DIRECTORY_SEPARATOR.'debug.log'); global $ld_sf_processing_id; if(empty($ld_sf_processing_id)) $ld_sf_processing_id = time(); if(isset($_GET['debug']) || $this->debug) error_log("[$ld_sf_processing_id] ".print_r($msg, true)); //Comment This line to stop logging debug messages. ini_set('log_errors', $original_log_errors); ini_set('error_log', $original_error_log); } function list_courses() { global $post; $postid = $post->ID; query_posts( array( 'post_type' => 'sfwd-courses', 'posts_per_page' => -1 ) ); $courses = array(); while ( have_posts() ) { the_post(); $courses[get_the_ID()] = get_the_title(); } wp_reset_query(); $post = get_post($postid); return $courses; } } // Remove Access to the course linked to the subscription key function remove_course_access( $user_id, $subscription_key ) { // Get the course ID related to the subscription $subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key ); $courses_id = get_post_meta($subscription['product_id'], '_related_course', true); // Update access to the courses if ($courses_id && is_array($courses_id)) { foreach ($courses_id as $course_id) { ld_update_course_access($user_id, $course_id, $remove = true); } } } // Give Access to the course linked to the subscription key function give_course_access( $user_id, $subscription_key ) { // Get the course ID related to the subscription $subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key ); $courses_id = get_post_meta($subscription['product_id'], '_related_course', true); // Update access to the courses if ($courses_id && is_array($courses_id)) { foreach ($courses_id as $course_id) { ld_update_course_access($user_id, $course_id, $remove = false); } } } new learndash_woocommerce();

        • ThomasLeCoz says

          August 13, 2015 at 10:01 am

          I can’t see why it’s not working from the get go :(

          Here’s how I would tackle the problem though :
          – activate the debug log in WP (wp-config) (this will create a log file in your wp-content/ dir)
          – output values in remove_course_access using error_log() to know when the function is triggered
          – create a dummy subscription and use the buttons in the admin panel (suspend – deactivate – etc.)

          I debugged most of my code this way, I’m sorry I don’t have the time to dive into yours right now but this is how I would research the issue.

          Also, let me know how it goes and if you have additional questions (or more specific due to the logs output).

          • MJ says

            August 13, 2015 at 5:33 pm

            Hi Thomas,

            Thank you so much for your reply. I activated the WP Debug and the error log, but I cannot figure out what you mean by “output values in remove_course_access using error_log() to know when the function is triggered”. I tried googling it and put this code in my functions.php:

            function log_me($message) { if (WP_DEBUG === true) { if (is_array($message) || is_object($message)) { error_log(print_r($message, true)); } else { error_log($message); } } } log_me($remove_course_access);

            But I got this notice in the debug log:

            PHP Notice: Undefined variable: remove_course_access in /*******/wp-content/themes/Avada-Child-Theme/functions.php on line 236

            [Note that no subscriptions have been expired yet (see my comments below), so I don’t know if that matters for this message.]

            So, I put the code instead into learndash_woocommerce.php, but I got a blank white screen.

            So, how exactly do I “output values in remove_course_access using error_log() to know when the function is triggered”?

            Also, it seems that subscriptions cannot be actually canceled or expired any earlier than 24 hours. Is there any way to change this for testing purposes? I seem to have to wait at least 24 hours every time I cancel a subscription in order to test removal.

            Thank you so much!

          • ThomasLeCoz says

            August 15, 2015 at 12:32 pm

            Hey MJ,

            I wasn’t thinking about putting code into functions.php but adding log output inside the WooCommerce-Learndash code to see where the program is going and if it’s triggering the right functions at the right time.

            I think the best option for you is to hire a dev for this task. You should be able to find one for a modest price on UpWork. Use this article as a step-by-step brief and ask him to proof-check your code this should get you sorted out.

            I’m sorry I can’t help more but this seems to be a specific issue and you need someone to dive into your code and check that everything is running smoothly. Outsourcing this is probably the most efficient course of action.

            Hit me up if you have additional questions, happy to help if I can :)

          • MJ says

            August 15, 2015 at 5:10 pm

            Oh bummer. I will see what I can do. I was hoping for a put _______ after _______ in _____.php to log output. I just put in something and I’ll see if it tells me anything.

          • MJ says

            August 16, 2015 at 1:32 am

            Nope and so far all the developers want to charge $300+. What a bummer.

          • ThomasLeCoz says

            August 17, 2015 at 7:44 am

            This is basically what you have to do. The thing is you need to figure out what’s going on by trying various possibilities and I can’t guide you from comments if Case #1 doesn’t work.

            I would start by making sure the remove_course_access function is triggered, so putting something like:

            error_log("Remove Course function triggered");

            After

            function remove_course_access( $user_id, $subscription_key ) {

            In learndash_woocommerce.php should help you see if it’s triggered (then test the various cases in your admin panel, pausing and cancelling subscriptions).

            If it’s not working — meaning nothing is output in the log file when you cancel / pause a subscription associated with a learndash course — I would investigate the hooks then.

            But again, this will go technical very quickly. I can’t provide a more general approach than the article I wrote above. It seems something isn’t working on your installation and I can’t figure out what from here.

            Hope this helps :)

          • MJ says

            August 17, 2015 at 10:17 pm

            Oh thank you so much, Thomas! I will try this out and I think it will help me figure out what’s wrong. Thanks again!

      • MJ says

        August 12, 2015 at 10:33 pm

        And the Deposits extension isn’t really what I’m looking for – I need the subscriptions one. :-/ I appreciate the recommendation, though.

      • MJ says

        September 14, 2015 at 7:50 pm

        Hi Thomas, I just wanted to let you know that Learn Dash support was able to replicate my issue with Learn Dash, WooCommerce, the LD/WC Integration, and your fix. Course removal not working for them either. They have added native integration to the roadmap, but I’m still looking for a fix in the meantime – my developers haven’t been able to figure it out.

        • ThomasLeCoz says

          September 14, 2015 at 7:57 pm

          Well, this spikes my curiosity… Can you email me the link to the LearnDash thread (thomas at thomaslecoz.com ) I’ll pop in (although I cannot promise a quick fix my schedule is crazy right now).

          • MJ says

            September 14, 2015 at 8:19 pm

            Sorry, I’ve been communicating with them via email for about a month now. I’ll send you the email chain, but I know a public forum would have been preferable.

          • ThomasLeCoz says

            September 14, 2015 at 8:23 pm

            Yeah, I hoped I could pick the LearnDash guys’ brain. Anyway, I’ve answered your email ;)

    • ThomasLeCoz says

      December 16, 2015 at 5:19 pm

      Hey MJ, hope you’re doing good. Quick reply to say that the article has been updated to the last version of my code wish fixes some issues :)

      • MJ says

        December 16, 2015 at 6:49 pm

        Thanks for the update, Thomas! I actually haven’t updated to Woocommerce Subscriptions 2.0 yet for fear of breaking everything we finally fixed. Since your section of code was added to my functions.php file which got it working, where would this new code go? learndash_woocommerce.php? And do you think updating to WS 2.0 would break anything again? :-/

        • ThomasLeCoz says

          December 16, 2015 at 6:55 pm

          Hey! This code has been tested on WP 4.3, WC 2.4.10, WS 2.0.6 and LearnDash 2.1.5

          Everything is in my learndash_woocommerce.php… Depends on what is inside your functions.php but you probably have send_receipt() inside learndash_woocommerce.php and give_course_access() inside functions.php. It would be my guess.

          Let me know if you have issues!

          • MJ says

            December 16, 2015 at 7:08 pm

            Thanks, Thomas!

          • MJ says

            January 18, 2016 at 8:46 pm

            Hi Thomas! So, I updated to Subscriptions 2.0.8 (well, someone who was supposed to be helping troubleshoot something did it for me before I had a chance to complete testing…) and my students aren’t getting removed from the courses again. :( Aaand their Paypal recurring payments aren’t getting canceled. Yay… I am seeing this in the error log (not sure if related to anything):

            PHP Notice: Undefined index: _related_course in /home/startasl/public_html/startasl/members/wp-content/plugins/learndash_woocommerce/learndash_woocommerce.php on line 63

            So, I’m going to have a good time troubleshooting again. :(

          • ThomasLeCoz says

            January 18, 2016 at 9:31 pm

            Hi, sorry to hear this :(

            Since the update (the article has been updated), everything is compatible and work perfectly on my sites, client sites and reader’s site so it might be a conflict with another plugin or a slight difference in the code…

            From the error you have, it looks like the product is not linked to the course in your WooCommerce products… but I could be mistaken.

            I have a crazy schedule right now, but could you send me a zip of your files + a WP admin access so I can have a look when I have a minute? I can’t spend hours on this but if I can spot the problem quickly enough, happy to help ;)

            I’ve just sent you an email so you can send everything through email.

  8. KatyJoyAlice says

    August 31, 2015 at 10:01 pm

    I have been adding this code to my client’s site. So far so good (and I’m not a PHPer!) Thanks for coding this.

    I have a course that runs for a year (well, my client does), so I have two payment options: Pay in full; or 3 monthly payments). I have created separate products for these (see the bottom of this page: http://mindfullifetoday.com/mindful-life-schools-weekly-wellness-program/) because I find the ‘variable subscriptions’ with a Pay in full and a 3 monthly installments set-up confusing and fraught with problems.

    My question is: Does the code you provided remove the use once the 3 months is up? In the Subscriptions area of the product set-up, I have $39 per month for Subscription Length: 3 months. I can’t seem to work out how to let someone pay over 3 months, but have access for a year.

    Any ideas?

    • ThomasLeCoz says

      September 1, 2015 at 7:34 am

      Hey KatyJoyAlice,

      Thanks for your message, glad this article helped you :)

      This article is about selling a course with a subscription, so when the subscription expires, so does the course access. BUT I’ve been in a similar situation for a client so I also wrote this one:
      http://thomaslecoz.com/sell-by-installments-with-woocommerce-subscriptions/

      You’ll find everything you need to make it happen. Please also note that I’ve written this before WooThemes released this plugin: http://www.woothemes.com/products/woocommerce-deposits/ which does about the same thing.

      Then for the 1 year duration of the course you can use the “Expire Access” option built in LearnDash in the Course menu.

      Let me know if I missed something :)

      • KatyJoyAlice says

        September 1, 2015 at 11:11 pm

        Thanks so much for the reply (and so quickly)! I actually looked at the Deposits plugin yesterday… but I couldn’t work out how to set it up so that there are automatic payments made, so for example, when month 2 payment is due, as I understand it, it’s up to the customer to login and pay. That sounds like a potential headache, chasing everyone for payments etc. Do you know if my understanding is correct – or did I miss something?

        • ThomasLeCoz says

          September 2, 2015 at 9:12 am

          Not sure, I haven’t used it yet and you’ll probably have to make sure it works well with LearnDash.

          I think it should disable access when expecting a payment that’s not coming so you don’t have to chase around the customer. But again, not field tested so I don’t want to speak about stuff I don’t know :p

  9. Santosh Kumar Korada says

    November 6, 2015 at 8:13 am

    Hi,
    Is there any plugin for subscription product with sign up fee in installment process, can you reply
    me

    • ThomasLeCoz says

      November 6, 2015 at 4:50 pm

      Hi Santosh,

      Not sure about your question. The WooCommerce Subscriptions plugin has a “sign up fee” feature if this is what you ask.

      So you can use this fix (actually, I haven’t updated it for WooCommerce Subscriptions 2.0) and just set a sign-up fee on your product. Everything will work fine, the code you see above is just hooked to the recurring subcriptions process so it won’t influence the sign-up fee or anything.

      Did I answer your question?

      • Santosh Kumar Korada says

        November 9, 2015 at 7:00 am

        Thanks for your reply.
        Actually I need to implement installment option for the signup fee for subscription products in my
        Woocommerce store…

  10. David Robinson says

    November 24, 2015 at 12:25 am

    This code no longer works unfortunately. I believe Learndash have updated their code so this code wont do anything.

    • ThomasLeCoz says

      November 24, 2015 at 12:43 am

      Hey David, most of the changes came from WooCommerce Subscriptions 2.0 actually.

      Preparing a fix for this week if I have the time (or next week if I don’t).

      Sorry for the inconvenience ;)

      • David Robinson says

        November 24, 2015 at 10:29 am

        Hi Thomas, Thanks for the super quick reply. I came to a false conclusion based on the dates of the posts here and the change to the Learndash code in September. Thats great if theres going to be a fix as I have moved over to Woocommerce subscriptions with Learndash and the only thing that doesnt work is removing users from courses. I’ll be keeping an eye on this page to see the results. Thanks again.

        • ThomasLeCoz says

          November 26, 2015 at 2:59 am

          Hey David, running some tests today everything worked ok regarding subscription cancellation and access management to courses.

          I still need to run more extensive tests (with multiple products, etc.) and there are still some updates overdue here (especially if you’re setting up a drip-fed course) but the code works on my test platform.

          Could you email me the details of your installation and what doesn’t work exactly? thomas [at] thomaslecoz [dot] com

          Let me know, this way I’ll get you sorted out ;)

    • ThomasLeCoz says

      December 16, 2015 at 5:20 pm

      The article has just been updated :)

  11. Anna says

    April 2, 2016 at 8:08 pm

    Could this also be solved by adding woocommerce memberships?

    • ThomasLeCoz says

      April 3, 2016 at 9:54 am

      Hi Anna,

      Depends on the plugin you’re using (there are severeal “WooCommerce Memberships” out there) and what you’re looking for. For the recurring billing, you’ll need WooCommerce Subscriptions (unless you go with the integrated platform in LearnDash, but it can be pretty limiting if you want to plug-in extensions like Social Checkout, Upsells, etc).

      • Bruce says

        May 4, 2016 at 2:22 pm

        Hi Thomas,

        This is a terrific resource, thank you!

        I wanted to follow up to Anna’s question, I think she means the actual WooThemes extension “WooCommerce Memberships” (https://www.woothemes.com/products/woocommerce-memberships/).

        I’m using Paid Memberships Pro to handle membership access AND take payments using Stripe but, I would also be very interested in moving the whole shebang to WooCommerce using Subscriptions and Memberships. This would then allow me to sell products without sending the client to a whole new system.

        Any advice or insight you may have would be greatly appreciated. Keep up the great work!

  12. Anudeep says

    May 1, 2016 at 9:34 pm

    Does this code still work the latest versions of LD, Woo commerce, and Woo commerce subscriptions plug in ? and what about the update process every time any of the these plug ins update themselves does the code need to be re written ?

    • ThomasLeCoz says

      May 4, 2016 at 4:47 pm

      Hey Anudeep,

      Sorry for the delay somehow comments weren’t on Disqus and ended up in the classic WordPress (aaaaah caching…).

      Yes, everything works so far and unless there are big modifications in LD or WooCommerce this piece of code will keep working. The code doesn’t need to be re-written as long as you don’t update the add-on on which you write the modifications (I based mine off of the Learndash WooCommerce add-on).

      Hope this helps.

  13. yaniksphotoschool says

    June 13, 2016 at 10:31 pm

    Hello Thomas

    I tried just to do the simple hack as I’m not a programmer but I don’t see the associated courses when I select Simple Subscription after saving the draft Course. Is this normal?

    • ThomasLeCoz says

      June 14, 2016 at 9:20 am

      Hi!

      I think you need your course to be published to have it displayed in the “Related Course” section :)

      If you don’t see a “Related Course” section in your product creation, check that you’ve done the modifications shown in the first section of this article (after “Prerequisites”).

      Let me know if it fixes it :)

      Cheers!

      • yaniksphotoschool says

        June 14, 2016 at 11:12 am

        Hi Thomas

        Thank you for responding so quickly.

        Yes, all my courses are published. :) And I see them all when I select Course (see attached).

        The weird thing is that even before finding your article, I could see the related courses in the Simple Subscription. Then I asked LearnDash if I was doing everything correctly and they told me they didn’t support WC Subs and to save it as a course. And when I did this, that’s when they all disappeared when I went back to Simple Subscriptions.

        I tried your steps twice on a new product to no avail.

        So now, not being a programmer, I modified the LD WC php file as you mentioned and I think it’s working. I would have liked you to verify my php file but I can’t seem to upload it here. :) Would you be so kind as to pop me an email at [email protected] so that I can show you my php file?

        Thank you so much for publishing this article. You’re saving me hours!!

        • ThomasLeCoz says

          June 14, 2016 at 4:06 pm

          Sorry but I can’t do this on a one to one basis (I try to when I have the time but June is crazy busy right now ;)).

          Here’s how you can test it out :
          1/ Create a 100% discount coupon in WooCommerce
          2/ Order your product using the coupon
          3/ Check for course access

          If this doesn’t work hit me up we’ll try to find out why ;)

          • yaniksphotoschool says

            June 14, 2016 at 8:25 pm

            It works! I think…. I got the WC order receipt via email but no link to go to the purchased subscription. It’s pretty confusing.

            How do customers know where to go to access the linked courses to the WC Subscription?

            Thank you so much for all your help!

          • ThomasLeCoz says

            June 15, 2016 at 8:19 am

            Sure :)

            You can use Custom Menus for logged in user (the Uncanny Owl LearnDash Toolit is great for this: https://wordpress.org/plugins/uncanny-learndash-toolkit/) and add a link in the Advanced fields of your product.

            I use both but there are also a ton of other ways, it’s more a WooCommerce and UX question.

  14. codehooligans says

    June 15, 2016 at 12:02 am

    Thanks for the details. I’ll be folding this code into the official Learndash-WooCommerce add-on in the next few weeks.

    One import note on some of your code. In the give_course_access_func.php gist you are directly accessing the post meta for the Course to update the access list. This is very bad.

    Leandash does provide a handy utility function for this very need:

    /**

    * Update list of courses users has access to
    *
    * @since 2.1.0
    *
    * @param int $user_id
    * @param int $course_id
    * @param bool $remove
    * @return array list of courses users has access to
    */
    function ld_update_course_access( $user_id, $course_id, $remove = false )

    Thanks.

    • ThomasLeCoz says

      June 15, 2016 at 8:24 am

      Great! I don’t remember why I didn’t use it (because I’ve seen the method and quite liked it…). I think I opened it up to understand it (I had problems with the drip-feeding access being reset at each new subscription renewal) and let it as is once it worked.

      Thanks for the heads up, I don’t know if I’ll have the time to clean up my code before you roll out the update, but I’ll make sure to update my post to the update post on LearnDash once you’ve announced compatibility with WooSubs.

      Hit me up if I can help ;)

    • bomakalu says

      June 27, 2016 at 9:51 am

      can you let us know when you have added this
      that would be fantastic
      many thanks

      • ThomasLeCoz says

        June 27, 2016 at 12:47 pm

        Hi Bomakalu, sorry you had to re-post your comment, Disqus and my caching plugin didn’t get along well yesterday. It’s fixed though ;)

    • KatyJoyAlice says

      September 9, 2016 at 1:19 pm

      Hi, any chance this has been updated in the latest LD-woocommerce add-on? While I’m so appreciative of this code, it’s tricky to implement for each new client I have that needs subscriptions, so I’m looking forward to it being integrated with the LD-WC plugin.

      • ThomasLeCoz says

        September 9, 2016 at 1:39 pm

        Hey Katy, I understand. The best source of info the LearnDash Add-ons is still the LearnDash forums over at support.learndash.com I know it’s in their dev pipeline but I’m not sure they release it yet (I’ve been a bit out of the e-learning industry for the last 6-8 months).

        • pranav sarnaik says

          September 20, 2016 at 5:13 am

          Hi thomas Sir,it would be great if you provide the learndash_woocommerce.php file with your code in it as it is difficult to know where to enter the code for layman like me .If you attach the learndash_woocommerce.php file will all your updated code in your post,it would be really useful

          • ThomasLeCoz says

            October 1, 2016 at 11:33 am

            Hi Pranav,

            I discussed including files here with the LearnDash team at the time of the release of this article and the best course was to keep everything under LearnDash’s roof for better support / updates (plus, most of the code is LearnDash’s property so I don’t feel like dumping it here).

            This is why my file isn’t included here (and won’t be). However, I know they’re working in integrating with WooCommerce Subscription so you should have an all-in-one download on your member zone in the future.

            Hope this helps!

  15. bo says

    June 27, 2016 at 8:17 am

    Hi there codehooligans

    This is excellent and would save a lot of heartache if you let us know when it is rolled into the official Learndash-WooCommerce add-on?

    Waiting on this many thanks

    bo

  16. Cathal McNamara says

    September 16, 2016 at 3:11 pm

    hi Thomas, firstly well done on your post. its straightforward and I was able to get it working (mostly). Right now I get an error 500 at the checkout page. On the backend the customer is created but they dont get emails confirming order. Also the subscription shows as pending. Any ideas?

  17. Gaorii Yoong says

    November 5, 2016 at 8:49 am

    Hello Thomas, thanks a bunch for this! I had the same issue (without the subscription part) and was very frustrated with myself. I’m very new to messing with WP and customizing plugins, so thank you!!

    • ThomasLeCoz says

      November 5, 2016 at 9:23 am

      Thanks for your comment, appreciate it. Glad I could help!

  18. harunb13 says

    April 11, 2017 at 10:35 am

    Hey Thomas, thanks a lot for this. Can you share script link for installment payment?

    • ThomasLeCoz says

      April 11, 2017 at 12:01 pm

      Hey Harunb, thanks for stopping by.

      I talked with the LearnDash team and we decided it was best to avoid sharing their WooCommerce + LD plugin (as most of the code is theirs). All of the tweaks are explained here though, as for the installment payment, you might want to have a look at this article I’ve written:
      https://thomaslecoz.com/sell-by-installments-with-woocommerce-subscriptions/

      Hope this helps!

  19. evelyn says

    May 7, 2017 at 5:13 am

    Hi
    It is hard to tell if these tweaks have been added to the learndash plugin. I thought that subscriptions would work with Learndash, but I’m not seeing clear instructions to implement it.

    Thanks,
    Evelyn

    • ThomasLeCoz says

      May 7, 2017 at 10:00 am

      Hi Evelyn,

      I wrote this article some time ago now, when WooCommerce Subscriptions and LearnDash weren’t compatible.

      It seems LearnDash is now compatible with it out of the box: https://www.learndash.com/add-on/woocommerce/

      If you have specific questions about the integration, the best way would be to approach Learndash’s team to know how integrated they are with WooCommerce Subscriptions.

      I hope this helps :)

  20. Sander de Brouwer says

    June 8, 2017 at 11:14 pm

    Hi couple of months ago i’ve implemented the code in the article with succes. Everything was working great. But now it seems that learn-dash came up with a better version for the plugin and that the implementation isn’t necessary anymore. So i’ve installed the plug-in and now nothing is working. Should I remove the code that i’ve entered to make the plug-in work? thanks for the reply.

    • ThomasLeCoz says

      June 9, 2017 at 8:29 am

      Hi Sander,

      Hard to say what happened here. My code doesn’t make any structural change to the database or the way data is accessed so it shouldn’t be hard to rollback to your previous setup if the problem is urgent.

      Otherwise, I’d check with the LearnDash team to get more information on their implementation of Subscriptions. Although it’s still working in many cases, my code starts to date a little bit and might call deprecated functions and methods from LearnDash’s code.

      So basically, I’d check with LearnDash see what’s the best way to make it work (and I’d go with their solution, limiting the number of third party plugins and plugin authors).

      Hope this helps!

      • Sander de Brouwer says

        June 9, 2017 at 10:39 pm

        Hi thomas,

        I wil just remove the steps of your setup, and continue with the learndash plug-in. Further I would just like to say that you code was doing perfect! And I really appreciate what you did because at that time it was a big problem…

        Many greets

        Sander

        • ThomasLeCoz says

          June 10, 2017 at 8:01 am

          Yes, this should work :)

          Thanks for the kind words Sander, appreciate it!

Copyright © 2025 · THOMAS LE COZ

Privacy Policy

Copyright © 2025 · Maker Pro on Genesis Framework · WordPress · Log in