1

I would like to adapt this code (which works on the single-course.php page) to work on the Single Lesson page (single-lesson.php):

<?php 
global $post, $current_user, $woothemes_sensei;
  $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
  if ( ! ( $is_user_taking_course  ) ) {
    echo "I am not taking course";
  } else {
    echo "I am taking the course";
  }
?>

From the documentation it seems that lessons have to belong to one course only, but how can this relationship between enrollment status be shown on the lesson page?

3

You can show enrolment status on the lesson page using sensei actions and function. you can display status before/after content using action. just use proper action and paste code in active theme's functions.php file.

To display before Lesson content use below action: add_action('sensei_single_lesson_content_inside_before','sensei_single_lesson_content_callback',100);

To display after Lesson content use below action: add_action('sensei_single_lesson_content_inside_after','sensei_single_lesson_content_callback',100);

Here is function which used for display status :

function sensei_single_lesson_content_callback($lessionid)
{
    $course_id = Sensei()->lesson->get_course_id( $lessionid);
    $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $current_user->ID );
    if ( ! ( $is_user_taking_course  ) ) {
        echo "I am not taking course";
    } else {
        echo "I am taking the course";
    }
}

You can take reference from above code to get specific course id using $course_id = Sensei()->lesson->get_course_id( $lessionid); just replace $lessionid with $post->ID in single-lesson.php file.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.