Created
November 29, 2021 06:32
-
-
Save ibrahim-kardi/9c6d14becd813aaf2daa46902f621b0b to your computer and use it in GitHub Desktop.
use this shortcode [own_enrolled_course_list]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The shortcode function | |
function tutor_current_user_enrolled_course_list() { | |
$my_courses = tutor_utils()->get_enrolled_courses_by_user(get_current_user_id(), array('private', 'publish')); | |
if ($my_courses && $my_courses->have_posts()): | |
while ($my_courses->have_posts()): | |
$my_courses->the_post(); | |
$avg_rating = tutor_utils()->get_course_rating()->rating_avg; | |
$tutor_course_img = get_tutor_course_thumbnail_src(); | |
$post = $my_courses->post; | |
$custom_url = home_url($post->post_type.'/'.$post->post_name); | |
?> | |
<div class="tutor-mycourse-wrap tutor-mycourse-<?php the_ID(); ?>"> | |
<a class="tutor-stretched-link" href="<?php echo esc_url($custom_url);?>"><span class="sr-only"><?php the_title(); ?></span></a> | |
<div class="tutor-mycourse-thumbnail" style="background-image: url(<?php echo esc_url($tutor_course_img); ?>)"></div> | |
<div class="tutor-mycourse-content"> | |
<div class="tutor-mycourse-rating"> | |
<?php tutor_utils()->star_rating_generator($avg_rating); ?> | |
</div> | |
<h3><a href="<?php echo esc_url($custom_url);?>"><?php the_title(); ?></a></h3> | |
<div class="tutor-meta tutor-course-metadata"> | |
<?php | |
$total_lessons = tutor_utils()->get_lesson_count_by_course(); | |
$completed_lessons = tutor_utils()->get_completed_lesson_count_by_course(); | |
?> | |
<ul> | |
<li> | |
<?php | |
_e('Total Lessons:', 'tutor'); | |
echo "<span>$total_lessons</span>"; | |
?> | |
</li> | |
<li> | |
<?php | |
_e('Completed Lessons:', 'tutor'); | |
echo "<span>$completed_lessons / $total_lessons</span>"; | |
?> | |
</li> | |
</ul> | |
</div> | |
<?php tutor_course_completing_progress_bar(); ?> | |
</div> | |
</div> | |
<?php | |
endwhile; | |
wp_reset_postdata(); | |
else: | |
echo "<div class='tutor-mycourse-wrap'><div class='tutor-mycourse-content'>".__('You haven\'t purchased any course', 'tutor')."</div></div>"; | |
endif; | |
} | |
// Register shortcode [own_enrolled_course_list] | |
add_shortcode('own_enrolled_course_list', 'tutor_current_user_enrolled_course_list'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment