You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our intended use, it is important that if a course enrollment expires, and the user re-enrolls, they have to start over. Thus, I'm trying to make a custom plugin that automatically deletes any cancelled enrollment, but the following Tutor LMS actions never seem to fire:
tutor_after_enrollment_cancelled
tutor/course/enrol_status_change/after
I have added debug code to every part of my custom code and I'm certain that the actions are not firing as they should. The plugin is being initialized correctly.
Moreover, in another custom plugin I'm making, I noticed that the tutor_after_enroll action is also not fired if the user PURCHASES the course instead of enrolling for free (in case the course is paid).
I have spent a lot of time trying to describe this to a support agent in a ticket (we have a Tutor LMS Pro subscription) but they either don't understand what I'm saying, they are not even reading what I'm sending, or the replies are AI-generated :/
My code (from the first section of my issue):
/**
* Plugin Name: Tutor Canceled Enrollment Cleaner
* Description: Permanently deletes Tutor enrollments when they are canceled.
* Version: 1.0.0
* Author: Ioannis Dressos
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class TutorCanceledEnrollmentCleaner {
public static function init() {
add_action( 'tutor_after_enrollment_cancelled', [ __CLASS__, 'auto_delete_enrollment' ], 10, 2 );
add_action( 'tutor/course/enrol_status_change/after', [ __CLASS__, 'auto_delete_enrollment_by_id' ], 10, 2 );
}
/**
* Automatically deletes the enrollment when it is canceled.
*
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
*/
public static function auto_delete_enrollment( $course_id, $user_id ) {
tutor_utils()->cancel_course_enrol( $course_id, $user_id, 'delete' );
}
public static function auto_delete_enrollment_by_id ( $enrol_id, $new_status ) {
$enrollment = tutor_utils()->get_enrolment_by_id( $enrol_id );
$course_id = $enrollment->course_id;
$user_id = $enrollment->student_id;
if ( $new_status === 'cancel' || $new_status === 'canceled' ) {
self::auto_delete_enrollment( $course_id, $user_id );
}
}
}
// Initialize the plugin.
TutorCanceledEnrollmentCleaner::init();```
The text was updated successfully, but these errors were encountered:
Another example of clean, simple code that is not working even though it should be:
<?php
/**
* Plugin Name: Tutor Re-Enroll Progress Reset
* Description: Resets user course progress when re-enrolling.
* Version: 1.0.0
* Author: Ioannis Dressos
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class TutorReenrollProgressReset {
public static function init() {
add_action( 'tutor_after_enroll', [ __CLASS__, 'reset_course_progress' ], 10, 2 );
add_action( 'tutor/course/enrol_status_change/after', [ __CLASS__, 'reset_course_progress_by_enrollment_id' ], 10, 2 );
}
public static function reset_course_progress( $course_id, $user_id ) {
tutor_utils()->delete_course_progress( $course_id, $user_id );
}
public static function reset_course_progress_by_enrollment_id ( $enrol_id, $new_status ) {
$enrollment = tutor_utils()->get_enrolment_by_id( $enrol_id );
$course_id = $enrollment->course_id;
$user_id = $enrollment->student_id;
if ( $new_status === 'completed' ) {
self::reset_course_progress( $course_id, $user_id );
}
}
}
// Initialize the plugin.
TutorReenrollProgressReset::init();
We need the actions fired appropriately regardless if enrollment/cancellation/deletion was done through the admin panel, in batch, from clicking the button (free courses), or by purchase.
In our intended use, it is important that if a course enrollment expires, and the user re-enrolls, they have to start over. Thus, I'm trying to make a custom plugin that automatically deletes any cancelled enrollment, but the following Tutor LMS actions never seem to fire:
I have added debug code to every part of my custom code and I'm certain that the actions are not firing as they should. The plugin is being initialized correctly.
Moreover, in another custom plugin I'm making, I noticed that the
tutor_after_enroll
action is also not fired if the user PURCHASES the course instead of enrolling for free (in case the course is paid).I have spent a lot of time trying to describe this to a support agent in a ticket (we have a Tutor LMS Pro subscription) but they either don't understand what I'm saying, they are not even reading what I'm sending, or the replies are AI-generated :/
My code (from the first section of my issue):
The text was updated successfully, but these errors were encountered: