最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Check if user has enrolled in Sensei LMS Course on Lesson Page

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Oct 15, 2019 at 8:17 Neil ScottNeil Scott 456 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 4

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)

  1. 暂无评论