Granting Course Registration on Purchase To Dynamic Courses

In some cases, you may want to determine within the manage order callback what courses to grant registration to.

For this, use a product custom field called bright_course_id_function:

The setting must be a function name.

Here's a sample function that fetches from the Bright Api a course which is the starting course for a path, as defined in the user's profile:

/* a callback function for use with http://help.aura-software.com/granting-course-registration-on-purchase-to-dynamic-courses/ */
function custom_get_course_ids($args) {
    $learnerId = Bright\extractFromArray($args,'learner_id');
    $learner = get_user_by('email', $learnerId);
    $path = get_user_meta($learner->ID, 'bright_path',true);

    $bright = \Bright\Wordpress::getInstance();

    if (!empty($path)) {
        $bright = \Bright\Wordpress::getInstance();

        $result = $bright->callApi('course',
        array('params' => array (
            'custom_re' => "{$path}\":1",
            'fields' => 'course_guid'
        )));

        if (!empty($result) && !empty($result[0])) {
            return array($result[0]->course_guid);
        }
    } else {
        $bright->log("No path found for user {$learnerId}");
        return null;
    }
}

In this example, the user has a profile field called bright_path, and will be assigned the first course from this path when they purchase this product.