LearnDash 다음 강의 링크 또는 코스가 시작되지 않은 경우 첫 번째 강의 링크 받기

[student][ld_next_lesson_link][/student][learndash_payment_buttons]
//LearnDash 다음 강의 링크 또는 코스가 시작되지 않은 경우 첫 번째 강의 링크 받기
function ld_next_lesson_link( $course_id = null ) {
	global $post;
	$user = _wp_get_current_user();

	if( is_null( $course_id ) ) {
		$course_id = learndash_get_course_id( $post );
	}

	if( !$course_id || !isset( $user->ID ) )  {
		// User Not Logged In OR No Course Identified
		return false;
	}

	$lessons = learndash_get_lesson_list( $course_id );
		
	if( !$lessons ) {
		// No Lesson
		return false;
	}

	$first_lesson = reset( $lessons );

	$user_course_progress = get_user_meta( $user->ID, '_sfwd-course_progress', true );

	if( isset ( $first_lesson->ID ) ) {
		// get first lesson link
		$lesson_id = $first_lesson->ID;
	}

	if( !$lesson_id ) {
		// No Lesson ID
		return false;
	}

	if( 'sfwd-lessons' != get_post_type( $lesson_id ) ) {
		// ID not for a Learndash Lesson
		return false;
	}

	$link = get_post_permalink( $lesson_id );
	return $link;
}

function shortcode_ld_next_lesson_link( $atts , $content = 'Next Lesson' ){
	extract(shortcode_atts(array(
		'course_id' => null ,
		'class' => 'learndash-next-lesson'
	), $atts));
	$url = ld_next_lesson_link( $course_id );
	if( $url ) {
		return '<a href="'.$url.'" class="'.$class.'">수강 시작</a>';
	}
	return false;
}
add_shortcode('ld_next_lesson_link', 'shortcode_ld_next_lesson_link');

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

위로 스크롤