Email notifications for Student sign-ups?

How do I get email notifications when a new person (student) signs up/enrolls in a class of mine?

  • Michael Bissett

    Hey @reneedoz, Michael here!

    This would be something that'd require some custom code to handle, one of our developers had come up with a means of doing this before, which I've updated for use in the current version of CoursePress Pro:

    add_action('coursepress_student_enrolled', 'cp_enrolled_in_course', 10, 2);
    function cp_enrolled_in_course($student, $c_id)
    {
        $course = new Course($c_id);
        $teachers = Course::get_course_instructors($c_id);
        $subject = __("You have new enrolled", 'cp');
        $headers = array(
            'Content-Type: text/html; charset=UTF-8'
        );
    
        $student_info = get_userdata( $student );
    
        $student_name = $student_info->user_firstname . ' ' . $student_info->user_lastname;
        $content = sprintf(__("Student %s has enrolled to your course %s", 'cp'), $student_name, $course->details->post_title);
        foreach ($teachers as $teacher) {
            wp_mail($teacher->user_email, $subject, $content, $headers);
        }
    }

    Insert that into either your theme's functions.php, or you can insert it as a mu-plugin.

    To create an mu-plugin, go to your /wp-content/ folder via FTP, and find the folder called "mu-plugins". If there is no folder with that name, then you'll want to create one. Then, create a file inside that folder, and give the file any name you like (making sure the file as an extension of .php, e.g. example.php) and paste the code in there.

    You don't need to activate that plugin, as it will be always be automatically activated. Please be sure to add a PHP start tag at the beginning of the code if you insert this code as a mu-plugin, like this:

    <?php

    Hope this helps!

    Kind Regards,
    Michael