Coursepress Pro Notification

Hi

Is it possible for an admin or instructor to receive a notification email when a student has completed a course?

I've seen similar posts asking for email notification when a student has enrolled, but the idea appears to have been in development for a long time.

This feature is really vital, saving the instructor having to login every time they want to check. Is this now possible? If not can I add this sorely missing feature to the request list!

Many thanks

  • Lindeni Mahlalela

    Hello Simon,

    I hope you are doing great so far. I have looked at the solution that was given and the coursepress plugin code.

    In the linked thread, a members said the code repeats sending emails I think that is due to the fact that the code is hooked to the "coursepress_set_unit_completed" which should run each time a unit is completed, so this means if the course has 10 units the code will send 10 emails and so that is the source of the many emails.

    If you'd rather have the emails when the whole course is completed, then the 'coursepress_set_course_completed' hook seems to be the best option as it will run only when the course is completed.

    So modifying the solution a little, you will have it look like this:

    add_action( 'coursepress_set_course_completed', 'send_email_to_student_when_coures_complete', 10, 2);
    function send_email_to_student_when_coures_complete( $student_id, $course_id) {
    
    }
  • Lindeni Mahlalela

    Hello Simon,

    I hope you are doing great so far. I have looked at the solution that was given and the coursepress plugin code. I am sorry to hear that that solution didn't work for you and would like to help.

    In the linked thread, a members said the code repeats sending emails I think that is due to the fact that the code is hooked to the "coursepress_set_unit_completed" which should run each time a unit is completed, so this means if the course has 10 units the code will send 10 emails and so that is the source of the many emails.

    If you'd rather have the emails when the whole course is completed, then the 'coursepress_set_course_completed' hook seems to be the best option as it will run only when the course is completed.

    So modifying the solution a little, you will have it look like this:

    add_action( 'coursepress_set_course_completed', 'send_email_to_student_when_coures_complete', 10, 2);
    function send_email_to_student_when_coures_complete( $student_id, $course_id) {
             $student           = new Student( $student_id );
    	$course            = new Course( $course_id );
    	$instructor_ids    = $course->get_course_instructors_ids();
    	$instructor_emails = array();
    	foreach ( $instructor_ids as $id ) {
    		$info                = get_userdata( $id );
    	 	$instructor_emails[] = $info->user_email;
    	}
    	//build the instructor email
    
    	//building parameters
    	$params = array(
    	 	'STUDENT_FIRSTNAME' => $student->first_name,
    	 	'STUDENT_LASTNAME'  => $student->last_name,
    	 	'COURSE_NAME'       => $course->details->post_title
    	);
    
    	$subject = 'your subject';
    	$body    = 'your body';
    	foreach ( $params as $key => $val ) {
    	 	$body = str_replace( $key, $val, $body );
    	}
    
    	$headers  = array(
    	         'Content-Type: text/html; charset=UTF-8',
    	 	'Cc: Admin Name <admin@email.com>'
    	);
    	$emails   = $instructor_emails;
    	$emails[] = $student->user_email;
    	wp_mail( $emails, $subject, $body, $headers );
    }

    Notice I have removed the following lines as we are not sending per unit but per course completed.

    Lines removed:
    $unit = new Unit( $unit_id );
    'UNIT_NAME' => $unit->details->post_title

    Please try that and let us know ho it works. Also please share with us what you tried with the original solution suggested by Denitsa in the link she provided, share with us what worked and what didn't work so that we can better understand your needs and problems you are facing, that will help us provide a better solution.

    I hope you enjoy your day further.

    Cheers,
    Mahlamusa

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.