Hello there, @chanart!
I have asked our developers to chime in, as this goes beyond my knowledge.
We’ll circle back to you as soon as we have info to share – thanks for bearing with us!
Hi @chanart
One option is to use the lesson progress repository. We keep a copy of the instance in the public property, so you can do something like that:
$progress = Sensei()->lesson_progress_repository->get( $lesson_id, $user_id );
If the progress exists for the user in the lesson, you get a progress object.
The described approach is a work in progress.
Another option is to use the old way of getting lesson status:
\Sensei_Utils::sensei_check_for_activity( array(
'type' => 'sensei_lesson_status',
'user_id' => $user_id,
'post_id' => $lesson_id,
) );
Hi Dmitry, thanks!
I tried the Sensei_Utils approach before and constantly got some errors. I found the lesson completion information in the wp_comments table and managed to retrieve it by creating the following function and then call it on a page in an if statement.. Seems to work 🙂
function has_approved_comment( $user_id, $post_id, $status = 'complete' ) {
$args = array(
'user_id' => $user_id,
'post_id' => $post_id,
'status' => $status,
'number' => 1, // Retrieve only one comment
);
$comments = get_comments( $args );
return ( count( $comments ) > 0 );
}
// And then run it on the page in an if statement on the page I want:
$current_user_id = get_current_user_id();
$post_id = get_the_ID();
if ( has_approved_comment( $current_user_id, $post_id, 'complete' ) ) {
echo "completed";
} else {
echo "in progress";
}
Hey @chanart,
Thanks for sharing this! it will be very helpful for other users if they need a solution like this.
You should be all set now! Happy to mark this as solved if you don’t have any further questions 🙂
Fantastic 🙂
I’m going to mark this thread as solved. If you have any further questions or need more help, you’re welcome to open another thread here. Cheers!