检查用户是否已注册课程页面上的Sensei LMS课程

时间:2019-10-15 作者:Neil Scott

我想将此代码(适用于single-course.php页面)改编为适用于single-Lesson页面(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";
  }
?>
从文档来看,课程似乎只能属于一门课程,但如何在课程页面上显示注册状态之间的关系?

1 个回复
最合适的回答,由SO网友:Chetan Vaghela 整理而成

您可以使用sensei操作和功能在课程页面上显示注册状态。您可以使用操作显示内容之前/之后的状态。只需在活动主题的函数中使用适当的操作和粘贴代码即可。php文件。

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";
    }
}
您可以参考上面的代码,使用$course_id = Sensei()->lesson->get_course_id( $lessionid); 只需更换$lessionid 具有$post->ID 在一节课中。php文件。

相关推荐