• Resolved sdwarwick

    (@sdwarwick)


    when a student is un-enrolled from a course for any reason, the progress information is not cleared. if the student is re-enrolled, student looks like they have already completed some of the course.

    need to clear all progress data associated with the student in the llms-meta database at an unenrollment event.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sdwarwick

    (@sdwarwick)

    Here is something I came up with – would appreciate a review/comment

    add_action( 'llms_user_removed_from_course', 'clear_enrollment_data', 10, 2 );
    
    function clear_enrollment_data($uid, $product_id)
    {
        global $wpdb;
    
        $course = new LLMS_Course( $product_id);
    	$lessons = $course->get_lessons( 'ids' );
    
        foreach ($lessons as $lesson) {
        $update = $wpdb->delete( $wpdb->prefix . 'lifterlms_user_postmeta',
                        array(
                            'user_id'      => $uid,
                            'post_id'      => $lesson  
                        ),
                        array( '%d', '%d' )
                    );
    
        }
    
                    return;
    };
    • This reply was modified 7 years, 9 months ago by sdwarwick.
    • This reply was modified 7 years, 9 months ago by sdwarwick.

    @sdwarwick,

    You solution appears like it will work, I didn’t run it but I read it and it looks sound. If it works it works!

    It’s questionable in my mind whether or not something like this should be added to the core. For example, if a recurring subscription expires, the user is “removed” from the course. If they fix their payment method and came back and their progress was lost they’d be pretty unhappy!

    In some scenarios it would absolutely make sense to remove this data. I’m imagining this would be especially useful for keeping the database uncluttered during testing.

    I’ll have to think on this but at the moment I can’t just drop it in. Certainly something we’ll consider how to handle better in the future though.

    Thanks and take care,

    Is there a way to include quiz results with this code? I need it so that only 1 quiz attempt is allowed per payment. If the student fails, then they have to pay again and their quiz results are reset.

    @sarahrgb,

    Quiz attempts are stored on the users postmeta table as per our description here: https://lifterlms.com/docs/lifterlms-database-description/#quiz-data

    If you wanted to delete quiz attempts when they repurchased you’d want to hook into the purchase complete event: https://github.com/gocodebox/lifterlms/blob/master/includes/controllers/class.llms.controller.orders.php#L125

    From there you can work your way into clearing the quiz data associated with the course they’re buying via a custom function.

    Hope that helps,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Delete all student progress when unenrolling student’ is closed to new replies.