Я пытаюсь реализовать функцию синхронизации уроков на своем веб-сайте, и это наполовину удалось, как показано в этой теме:
Синхронизировать статус завершения урока между всеми курсами в LearnDash >
Однако, хотя я могу синхронизировать статус завершения урока между всеми связанными курсами, я не могу реализовать то же самое, когда дело доходит до синхронизации статуса «незавершен».
Я пытался отразить код из ответа на вопрос в ссылке, используя соответствующие хуки и функции, но изменения не отражаются:
Пользовательская функция, позволяющая отмечать все уроки как незавершенные
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);
Изменить: я заметил избыточность во второй функции ниже, вызванную двумя циклами ранее, которые я также обновил в ссылке, упомянутой выше, а также изменил код на основе предложений @Anh Tuan Hoang.
Пользовательская функция, позволяющая отмечать все уроки как незавершенные
function custom_learndash_mark_lesson_incomplete($id, $lesson_id, $user_id) {
// Retrieve the user's progress for the specific course
$user_progress = learndash_user_get_course_progress($user_id, $id, 'legacy');
// Check if the user has progress for the lessons in the course and update it
if (isset($user_progress['lessons'])) {
// Remove the lesson from progress (mark as incomplete)
unset($user_progress['lessons'][$lesson_id]);
// Reduce the number of completed lessons
$user_progress['completed'] -= 1;
// Update the last completed lesson ID to the last lesson in the array
$user_progress['last_id'] = array_key_last($user_progress['lessons']);
}
// Retrieve the user's meta and course progress
$usermeta = get_user_meta($user_id, '_sfwd-course_progress', true);
$course_progress = $usermeta;
// Update the progress for the specific course
if (isset($course_progress[$id])) {
$course_progress[$id] = learndash_course_item_to_activity_sync($user_id, $id, $user_progress, $course_progress[$id]);
} else {
$course_progress[$id] = $user_progress;
}
// Save the updated course progress
update_user_meta($user_id, '_sfwd-course_progress', $course_progress);
// Mark the lesson as incomplete for the specific course
learndash_process_mark_incomplete($user_id, $id, $lesson_id);
// Update group progress if necessary
learndash_update_group_course_user_progress($id, $user_id);
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... -learndash
Синхронизировать статус незавершенного урока по всем курсам в LearnDash. ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение