• Resolved rgkmedia

    (@rgkmedia)


    Am trying to add the option of enrolling for a course, either with or without online tuition. Have created two separate courses and am trying to add some code that causes enrolling for the one course to trigger enrolling for the other course. I’ve tried changing the $course_id but this causes the whole enrolling process to fail.
    What is the simplest way to implement this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Bob

    (@prasunsen)

    Catch action “namaste_entrolled_course”, it’s documented in https://namaste-lms.org/developers.php

    Then call NamasteLMSCourse -> enroll() method.
    The method is not static so make sure you instantiate the class first:

    $_course = new NamasteLMSCourse();
    $_course->enroll($student_id, $course_id, ‘enrolled’);

    Thread Starter rgkmedia

    (@rgkmedia)

    Thanks for that. Have been trying to get something working the last few days but so far no luck.
    By ‘NamasteLMSCourse()’ I presume you mean NamasteLMSCourseModel()?
    Also the function enroll seems to call the action “namaste_entrolled_course”.
    The biggest problem is knowing where exactly to add any code. It’s never a good idea to call a function from within the function (enroll) or create a new instance within NamasteLMSCourseModel().
    The only other locations I cna think of are either where the enrolling text is changed to “You are enrolled in this course” or possibly the Post associated with the course, except the syntax ‘->’ causes the enroll function to just appear on the page as text.

    The code I’ve been trying is :-

    $course_id= “624”;
    $_course = new NamasteLMSCourseModel();
    $_course->enroll($student_id, $course_id, ‘enrolled’);

    Any suggestions?

    Plugin Author Bob

    (@prasunsen)

    Yes NamasteLMSCourseModel.
    Why is not a good idea to create a new instance? This is the only way to do it.

    Enrolling in course 1: Namaste calls “namaste_entrolled_course”.
    You catch this action. Create instance of NamasteLMSCourseModel and enroll the same student in course 2.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘enrolling for one course enrolls for another’ is closed to new replies.