Auto enroll not long working on coursepress 2


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.

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


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) {


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

Any ideas??