• Hello, I am currently trying to display a user’s wishlist courses via a shortcode. I have code below that I have been modifying, however, I believe the error in pulling the wishlist courses back is coming from the ‘tutor-utils()->get_wishlist($user_id)’ line below. Would you have any recommendations as to how to approach this? Or if the wishlist info for a user is stored off-site from Worpress, how would I query to that? Thank you!

    /**
    * 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="ians-course-wrapper">
    
    	<?php
        $user_id = get_current_user_id();
    	$my_courses = tutor_utils()->get_wishlist($user_id);
    	
    	if ($my_courses && $my_courses->have_posts()):
    		while ($my_courses->have_posts()):
    			$my_courses->the_post();
                $post = $my_courses->post;
    			?>
                
    
                        <a href="<?php the_permalink();?>"><?php the_post_thumbnail('thumbnail'); ?><?php the_title(); ?></a>
           
                    
    			<?php
    		endwhile;
    
    		wp_reset_postdata();
        else:
            echo "<div class='tutor-mycourse-wrap'><div class='tutor-mycourse-content'>".__('You haven\'t enrolled in any courses.', 'tutor')."</div></div>";
    	endif;
    
    	?>
    
    </div>
    <?php }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Dear @ianharris02

    I think you are using old version Tutor LMS template codes for the shortcode, that’s why you are facing the issue. If you want to create a shortcode for the Wishlist course then please use this file code

    /wp-content/plugins/tutor/templates/dashboard/wishlist.php

    Thank you

    Thread Starter ianharris02

    (@ianharris02)

    Hello,

    I am using the up to date wishlist.php file. Initially, I got the code for a shortcode that you posted a couple of months ago for enrolled courses, but I modified so that I could get the look that I was hoping to achieve.

    Now what I am trying to do is instead of using the enrolled courses for a user, I would like to gather a user’s wishlist courses instead. What I am stuck on is how you referenced a user’s wishlist courses to be able to display them. That what I am trying to figure out using the wishlist.php file; I saw the get_wishlist function in the wishlist.php file, but it only has null, and then two pagination variables which I don’t need because I would like to not include pagination.

    What I am hoping you can answer is what input would I need for the get_wishlist function to pull a user’s wishlist courses? I tried using the user’s ID, but the site errored unfortunately. Thank you in advance.

    Thank you for your time,
    Ian

    Dear @ianharris02

    I think you are using the code the Wrong way you need to use this file’s /tutor/templates/dashboard/wishlist.php all the PHP code to create shortcode to show wishlist courses.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Wishlist Items from Shortcode’ is closed to new replies.