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 badges1 Answer
Reset to default 4You 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.