Attempting to auto register people on CoursePress

Hi I am trying to automatically register people signing up on http://nourishinglife.com/courses-signup to the singular course I have available currently. The problem I am having is that I don't want people who sign up for a wordpress account via other methods (such as purchasing a product from our shop) to be automatically enrolled in the course.

We are not charging for courses on my site (they are charged through mindbodyonline and also charged in person at the studio). I want people who sign up through mindbody to just go to the link I give them and be automatically enrolled. I know this isn't the most efficient method of enrolling students, but my client wants it done this way for reasons.

I am using this code:

add_action('ms_model_member_create_new_user', 'enroll_for_all');
	function enroll_for_all($user_id)
	{
		$student = new Student($user_id->id);
		$courses = new WP_Query(array(
			'post_type' => 'course',
			'nopaging' => true,
			'status' => 'publish'
		));

    foreach ($courses->get_posts() as $course) {
        $student->enroll_in_course($course->ID);
    }
}

Any help would be appreciated, thank you.

  • Rupok

    Hi JR,

    Thanks for asking but I'm afraid, this is beyond my expertise. So I'm pinging one of our SLS (Second Level Support) heroes to have a look at this and help you in achieving your target.

    Please keep in mind, our SLS guys work around the clock and they have to deal with lots of critical issues and other things. So it may take a little while for them to check this and provide a feedback.

    Have a nice day. Cheers!
    Rupok

  • Panos

    Hi JR ,

    I suppose using a custom field in your registration form would be enough. I'm not sure if you are using any plugin for registration page.

    The concept is to add a custom field which you can check on registration hook. In my example I will add a custom field in the registration page of coursepress (http://yoursite.com/courses-signup/).

    The field name will be "wpmudev_is_cp_reg_page" and will have a value "yes", then on registration we can check if the value of that field:

    function wpmudev_coursepress_after_submit_custom_field(){
    
    	echo '<input type="hidden" name="wpmudev_is_cp_reg_page" value="yes"/>';
    
    }
    
    function wpmudev_enroll_on_cp_registration( $user_id ) {
    
        if( !isset( $_POST['wpmudev_is_cp_reg_page'] ) || $_POST['wpmudev_is_cp_reg_page'] != 'yes' ) return;
    
    	$student = new Student($user_id);
    	$courses = new WP_Query(array(
    		'post_type' => 'course',
    		'nopaging' => true,
    		'status' => 'publish'
    	));
    
    	foreach ($courses->get_posts() as $course) {
    	    $student->enroll_in_course($course->ID);
    	}
    
    }
    
    add_action( 'coursepress_after_submit', 'wpmudev_coursepress_after_submit_custom_field' );
    add_action( 'user_register', 'wpmudev_enroll_on_cp_registration', 10, 1 );

    Hope this helps!

    Thanks!
    Panos

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.