Sync lesson incompletion status across all courses in LearnDash

I'm trying to implement a lesson syncing feature in my website, which was half successful as shown in this thread: Sync lesson completion status across all courses in LearnDash However, while I'm able to sync the completion status of a lesson across all associated courses, I'm unable to implement the same when it comes to syncing the "incomplete" status. I tried to mirror the code from the answer to the question in the link using appropriate hooks and functions, but the changes are not reflecting: A custom function to mark all lessons as incomplete function nzf_sync_lesson_incompletion($user_id, $course_id, $lesson_id){ if(!empty($lesson_id)){ $shared_courses = learndash_get_courses_for_step($lesson_id, true); //Loop through the shared courses foreach ($shared_courses as $shared_course_id => $value){ // Skip the current course if($shared_course_id == $course_id){ continue; } // Mark the lesson as incomplete for the user for the concurrent shared course custom_learndash_mark_lesson_incomplete($shared_course_id, $lesson_id, $user_id); } } } add_action('learndash_mark_incomplete_process', 'nzf_sync_lesson_incompletion', 8, 3); Here is the code I used to mark each lesson incomplete: function custom_learndash_mark_lesson_incomplete($id, $lesson_id, $user_id){ //retreive current course progress $user_progress['course'][$id] = learndash_user_get_course_progress($user_id, $id, 'legacy');//LDBI if (isset($user_progress['course'][$id]['lessons'])){ //update lessons progress to complete $user_progress['course'][$id]['lessons'][$lesson_id] = 0; } $processed_course_ids = []; if ((isset($user_progress['course'])) && (!empty($user_progress['course']))) { $usermeta = get_user_meta($user_id, '_sfwd-course_progress', true); $course_progress = $usermeta; $course_changed = false; // Simple flag (indicator) to let us know we changed the quiz data so we can save it back to user meta. foreach ($user_progress['course'] as $course_id => $course_data_new) { $processed_course_ids[intval($course_id)] = intval($course_id); if (isset($course_progress[$course_id])) { $course_data_old = $course_progress[$course_id]; } else{ $course_data_old = []; } $course_data_new = learndash_course_item_to_activity_sync($user_id, $course_id, $course_data_new, $course_data_old); $course_progress[$course_id] = $course_data_new; $course_changed = true; } if (true === $course_changed) { update_user_meta($user_id, '_sfwd-course_progress', $course_progress); } } if (!empty($processed_course_ids)) { foreach (array_unique($processed_course_ids) as $course_id) { learndash_process_mark_incomplete($user_id, $course_id, $lesson_id); learndash_update_group_course_user_progress($course_id, $user_id); } } }

Comment (0)

You’ll be in good company