How to modify the function of the default theme

Hello. I want to modify the Enroll button in the course about page.

Based on the documentation, I can override its layout through comprehensive theming. But what if I want to modify how the button actually works? For example, when the Enroll button is clicked by a learner, instead of directing the learner into an e-commerce page for payment, it will automatically perform the API call of add_enrollment (refer to the api-docs). HOW CAN I ACHIEVE THIS?

Hi @Engr_James_Lusuegro :smile:

You can disable ecommerce checkout by following these steps:

  1. Login to your LMS as a superuser.
  2. Visit your Django Admin > Commerce > Commerce configuration (https://<your-lms-url>/admin/commerce/commerceconfiguration/add/)
  3. Edit the existing configuration, and un-check the “Checkout on ecommerce service” flag. Save.

If you don’t have an existing Commerce configuration, then ecommerce is already disabled on your deployment, and enrollments should already be going straight to the registration API (ref `course_about.html template file).

1 Like

Thank you for your reply. But I don’t want to disable the ecommerce completely. I just want this to occur in a specific course, not in all courses.

Hi @Engr_James_Lusuegro , then you should be able to override the course_about.html template file in your theme.

You should be able to copy the existing lms/templates/courseware/course_about.html template to your <THEME_BASE_DIR>/lms/templates/courseware/course_about.html, as illustrated by the stanford theme.

Then, modify the template logic that produces the “Enroll Now” button to check the course ID:

          <%
            href_class = "register"
            reg_href="#"
            if ecommerce_checkout and course.id not in [
               "course-v1:my+course+id",
               "course-v1:my+othercourse+id",
            ]:
              reg_href = ecommerce_checkout_link
              if single_paid_mode:
                href_class = "add-to-cart"
          %>
          <a href="${reg_href}" class="${href_class}">
            ${_("Enroll Now")}
          </a>
1 Like

The same idea of your answer works. Thank you for your assistance.

1 Like