• Hello, I found a similar topic that was open last year regarding this, but I have a few questions about it. One of the plugin supporters said to use this code and then enter the shortcode [enrolled-course] to display a user’s enrolled courses. I entered the shortcode, but there is information missing from it such as the background image and the start learning button. Do you have any adaptations to the code below that you would recommend trying? Thank you in advance!

    /**
    * Enrolled Course Shortcode
    */
    
    function tutor_enrolled_course_register_shortcodes() {
        add_shortcode( 'enrolled-course', 'shortcode_tutor_enrolled_course' );
    }
    add_action( 'init', 'tutor_enrolled_course_register_shortcodes' );
    
    /**
     * Shortcode Callback
     */
    
    function shortcode_tutor_enrolled_course( $atts ) {
        ?>
    
    <h3><?php _e('Enrolled Courses', 'tutor'); ?></h3>
    
    <div class="tutor-dashboard-content-inner">
    
    	<?php
    	$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();
                /**
                 * wp 5.7.1 showing plain permalink for private post
                 * since tutor do not work with plain permalink
                 * url is set to post_type/slug (courses/course-slug)
                 * @since 1.8.10
                */
                $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;
    
    	?>
    
    </div>
    <?php }
Viewing 7 replies - 1 through 7 (of 7 total)
  • Dear @ianharris02

    We have updated our template and design, that’s why this code will not work. You need to create a new shortcode using our new templates.

    Have a good day.

    Thread Starter ianharris02

    (@ianharris02)

    Hello there,

    Would you have an updated version of this code somewhere? I am not familiar with all of the class containers to rebuild the shortcode. Could it be adapted to fit with the new criteria?

    Thank you for your time,
    Ian

    Dear @ianharris02

    You have created a new shortcode using this template file.

    /tutor/templates/dashboard/enrolled-courses.php

    Have a good day.

    Hi, I have added this code to the file according to the last comment (/tutor/templates/dashboard/enrolled-courses.php), but still not working when I try to add [enrolled-course] shortcode on the page.

    Can anyone help with this function?

    Thanks,
    Phoebe

    Dear @phoebechirps

    You have to create a new shortcode using these file codes /tutor/templates/dashboard/enrolled-courses.php

    Have a good day.

    Yes I need to only display a students enrolled courses. How is this possable? Thank you support.

    Plugin Support Md. Jobayer Al Mahmud

    (@jobayertuser)

    hello @beinfinite

    If you know about creating a shortcode then go to the mentioned file and pick up the code of the only enrolled student and create a shortcode with that.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Use Shortcode for Enrolled Courses’ is closed to new replies.