<?php
// get the user’s viewed lessons
$user_id = get_current_user_id();
$viewed_lessons = get_user_meta($user_id, 'wpc-lesson-tracking', true);
// get the last viewed lesson
$last_viewed_id = null;
if(!empty($viewed_lessons)){
$last_viewed_id = $viewed_lessons[0][‘id’];
}
// get previous and next IDs
$wpc_courses = new WPC_Courses();
$ids = $wpc_courses->get_previous_and_next_lesson_ids($last_viewed_id);
// echo previous lesson link if exists
if($ids['prev_id'] !== false){
echo '<a href="' . get_permalink($ids['next_id']) . '">Prev</a>';
}
// echo next lesson link if exists
if($ids['next_id'] !== false){
echo '<a href="' . get_permalink($ids['next_id']) . '">Next</a>';
}
?>