Auto enroll not long working on coursepress 2

Hi,

I use woocommerce and coursepress.

I have Tim courses therefor 2 products.

A user purchases the course using a simple link that then takes them to the woocommerce checkout page.
https://my.domain.com/checkout?add-to-cart=PRODUCT_ID

I previously used the following function to auto enroll after purchase however this seems to have broken with Coursepress 2.

<?php

add_action('user_register', 'wpmudev_enroll_for_all', 20);
function wpmudev_enroll_for_all($user_id)
{	

    $student = new Student($user_id);

    global $wpdb;
    $course_type = 'course';

    $courses = $wpdb->get_results(
	    $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts WHERE post_type='%s' LIMIT 10", $course_type )
	 );

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

}
?>

This now causes an Internal Server Error when attempting to complete payment.

Any ideas??