title: Is there a way to unenroll students in LifterLMS when a subscription is cancelled in WooCommerce?
body: <p>I'm trying to write a php code to enable the system to unenroll students automatically when the user unsubscribes to a course in LifterLMS. This also means that they would not have to continue paying fees to WooCommerce. Is there any way I can do this? I wrote a php code to be added to functions.php but it is not working.</p>
  <pre><code>add_action( 'llms_unenroll_student', 'unenrol_when_cancelled' );
  function unenrol_when_cancelled(){
      $user_id = get_current_user_id();
      $user_subscriptions = wcs_get_users_subscriptions($user_id);
  
      
      $customer_orders = get_posts( array(
          'numberposts' =&gt; -1,
          'meta_key'    =&gt; '_customer_user',
          'meta_value'  =&gt; $user_id,
          'post_type'   =&gt; 'shop_order', // WC orders post type
          'post_status' =&gt; 'wc-cancelled' // Only orders with status &quot;cancelled&quot;
      ) );
      
      $subscriptionlist = [];
      foreach ($customer_orders as $subscription){
          $subscriptionlist[] = $subscription-&gt;get_id(); 
        }
  
      foreach ($subscriptionlist as $subscriptionid){
          if ($subscriptionid == '3400' || $subscriptionid == '74'){ 
              llms_unenroll_student($user_id, 7140, $new_status, $trigger);
              llms_unenroll_student($user_id, 7099, $new_status, $trigger);
              llms_unenroll_student($user_id, 6487, $new_status, $trigger);
              llms_unenroll_student($user_id, 6388, $new_status, $trigger);
  
              llms_unenroll_student($user_id, 7061, $new_status, $trigger);
              llms_unenroll_student($user_id, 7014, $new_status, $trigger);
              llms_unenroll_student($user_id, 5580, $new_status, $trigger);
              llms_unenroll_student($user_id, 5167, $new_status, $trigger);
  
              llms_unenroll_student($user_id, 6992, $new_status, $trigger);
              llms_unenroll_student($user_id, 6962, $new_status, $trigger);
              llms_unenroll_student($user_id, 6895, $new_status, $trigger);
              llms_unenroll_student($user_id, 6729, $new_status, $trigger);
          } elseif ($subscriptionid == '3136'){
              llms_unenroll_student($user_id, 5665, $new_status, $trigger);
          }
      }
  }
  </code></pre>