Questions about CoursePress using Membership 2 Pro

I'm building my online school and membership using coursepress and membership2, I'm using the coursepress theme as well. I want to get rid of the 'enroll now' process for members, I want the courses available without enrollment. Now once a user registers to a membership, he has to click 'enroll now', then 'start learning' before starting the course even after buying a course or courses and I would like to let them have access to the courses directly after they register to a membership.

2. I’ve been working on a series of 120 classes, created a course each in coursepress and I'd like them to be all visible on a 'single page', grouped by categories, for easy browsing, instead of having 12 pages to go through to find a specific course. What I want is a compact view, to see the 120 courses almost at a glance. Can I display a category cloud?

  • Predrag Dubajic

    Hey Christian,

    Hope you're doing well :slight_smile:

    Enrolling users based on the membership is not possible directly from plugin option I'm afraid but we had similar request before and solution from this thread should help out with that:
    https://premium.wpmudev.org/forums/topic/enroll-specific-membership-in-a-single-coursepress-course#post-1225325

    2. I’ve been working on a series of 120 classes, created a course each in coursepress and I'd like them to be all visible on a 'single page', grouped by categories, for easy browsing, instead of having 12 pages to go through to find a specific course. What I want is a compact view, to see the 120 courses almost at a glance. Can I display a category cloud?

    CoursePress comes with a Course Category widget which you can use to show the category cloud, only thing we need is to place it inside the content itself.
    You can do that with a plugin like this one https://wordpress.org/plugins/widget-shortcode/ that will allow you to add any widget as a shortcode in page content.

    Would that do the trick? :slight_smile:

    Best regards,
    Predrag

  • Cg

    hi, thanks for the help, we tried that (enrollment process) fix with violeta from support, it didn't work, could you go ahead and apply the fix for me?

    About the category cloud: excellent, where do I paste the shortcode precisely, when I create a new page?

    What I'd like is to have my 120 courses visible 'at a glance' for easy browsing, without having to scroll through 12 pages. It's not about infinite scrolling, more about the size of the course titles allowing for more to fit in a page.

  • Predrag Dubajic

    Hi Christian,

    I checked with Ashok that provided the initial code and it looks like that will not indeed work with the latest CoursePress version.
    However with a small change this should do the trick:

    <?php
    add_action(
        'ms_model_relationship_create_ms_relationship_before',
        function( $membership_id, $user_id, $gateway_id, $move_from_id ) {
            /**
             * 'membership_id' => 'course_id',
             */
            $array = array(
                '1220' => '1109',
                '2341' => '265',
                '2763' => '165'
            );
    
            CoursePress_Data_Course::enroll_student( $user_id, $array[$membership_id] );
        },
        99, 4
    );

    You can add that code as an mu-plugin and make sure to update the IDs of the courses and memberships.
    It's this part here:

    $array = array(
        '1220' => '1109',
        '2341' => '265',
        '2763' => '165'
    );

    Numbers on the left are the Membership ID's and the numbers on the right is Course ID to which the membership will enroll members to.
    For example, in the above, users that subscribe to membership with ID 1220 will be enrolled in course with 1109 ID.

    Let us know if this new code does the trick, but please note that this is not a "fix", as there's nothing wrong with the process as that's how the plugin works so this is a custom workaround for your specific case.

    Best regards,
    Predrag

  • Cg

    Just tried this with chat support, to no avail....
    from chat support:

    " Ok I have tried to upload the code and also used your membership id and course id. As this is not working I will suggest you to reply with this in the topic as the level of troubleshooting surpasses the scope of chat here. And please also mention there that you need all your 120 courses to be free from enrollment for the one membership that has id 135."

  • Panos

    Hey Christian ,

    Not sure how you have been testing it. This sniped provided in this thread should be working when adding new memberships to members and depending the membership id it enrolls to specific course.

    So one alternative is to change the above snippet to :

    add_action(
        'ms_model_relationship_create_ms_relationship_before',
        function( $membership_id, $user_id, $gateway_id, $move_from_id ) {
    
            if( ! ms_has_membership( 135 ) ){
                //OR check if $membership_id is 35
                return;
            }
    
            $post_args = array(
                'post_type' => CoursePress_Data_Course::get_post_type_name(),
                'post_status' => 'publish',
                'posts_per_page' => -1,
            );
            $courses = new WP_Query( $post_args );
    
            foreach( $courses->posts as $course ){
                if( ! CoursePress_Data_Course::student_enrolled( $user_id, $course->ID ) ){
                    CoursePress_Data_Course::enroll_student( $user_id, $course->ID );
                }
            }
        },
        99, 4
    );

    When adding a new membership to a member it checks if member has the membership 135. If he does the member gets enrolled to all courses.

    Second option is to do this check each time a member visits a course page in front end :

    add_action( 'template_redirect', function(){
    
        if( ! is_user_logged_in() || ! is_singular( CoursePress_Data_Course::get_post_type_name() ) ){
            return;
        }
    
        add_filter( 'ms_model_member_allowed_status', function(){
            return array( MS_Model_Relationship::STATUS_ACTIVE );
        } );   
    
        global $post;
    
        $student_id = get_current_user_id();
        $course_id = $post->ID;
    
        if( CoursePress_Data_Course::student_enrolled( $student_id, $course_id ) ){
            return;
        }
    
        //if ( ms_has_membership(100,110) ) Current user has membership 100 or 110?
        if( ! ms_has_membership( 135 ) ){
            return;
        }
    
        CoursePress_Data_Course::enroll_student( $student_id, $course_id );
    
    }, 10 );

    This checks if member has membership 135 and enrolls to current course only.

    Hope this helps :slight_smile:

    Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.