• Resolved Rics

    (@rics)


    I need that users must be enrolled (not only logged in) in a Course to see the Lesson content. They are all free courses… How can I force that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can either override the templates, e.g. single-lesson.php and put in a check or you can hook into the “sensei_can_user_view_lesson” filter. Something like this in your functions.php:

    function my_theme_only_show_content_for_enrolled_user( $can_view_lesson, $lesson_id, $user_id ) {
       if ( $can_view_lesson ) {
          $course_id = Sensei()->lesson->get_course_id( $lesson_id );
          $can_view_lesson = Sensei()->course->is_user_enrolled( $course_id, $user_id );
       }
       return $can_vew_lesson;
    }
    add_filter('sensei_can_user_view_lesson', 'my_theme_only_show_content_for_enrolled_user", 3, 10);

    NOTE: I’m just typing out of my head but it can hopefully get you started. I.e. the code is totally untested (but works in theory ?? )

    • This reply was modified 3 years, 1 month ago by hliljegren.
    Thread Starter Rics

    (@rics)

    Thanks A LOT!!! I will test it tomorrow and as soon as I get I working I will post the results here. ??

    Hi @rics ,

    You can also use conditional content, as seen here:

    https://senseilms.com/2021/02/09/all-new-conditional-content-lesson-actions-blocks/

    Thanks for the snippet, @hliljegren !

    Best,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Users must be enrolled in Course to see Lesson content’ is closed to new replies.