Title: PHP Function to enroll user
Last modified: March 28, 2022

---

# PHP Function to enroll user

 *  [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [4 years ago](https://wordpress.org/support/topic/php-function-to-enroll-user/)
 * Hi there,
 * Is there a function that allows me to easily enroll users to a course?
 * Something like `learnpress_enroll_user( $user_id, $course_id )` or do I have 
   to create an order inside LearnPress to enroll the user in my custom plugin?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [brianvu-tp](https://wordpress.org/support/users/briantp/)
 * (@briantp)
 * [4 years ago](https://wordpress.org/support/topic/php-function-to-enroll-user/#post-15504532)
 * Hi,
 * You can go to LearnPress -> Order then create the order for the user to they 
   can enroll on the course.
 * Thanks
 *  Plugin Support [brianvu-tp](https://wordpress.org/support/users/briantp/)
 * (@briantp)
 * [4 years ago](https://wordpress.org/support/topic/php-function-to-enroll-user/#post-15509466)
 * You can refer use to this code to meet
 *     ```
       $controller = new LP_REST_Courses_Controller();
       		$request    = new WP_REST_Request();
       		$request->set_param( 'id', $course_id );
       		$response    = $controller->enroll_courses( $request );
       ```
   
 * variable $user will auto get via function “learn_press_get_current_user”

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘PHP Function to enroll user’ is closed to new replies.

 * ![](https://ps.w.org/learnpress/assets/icon-256x256.gif?rev=3254420)
 * [LearnPress - WordPress LMS Plugin for Create and Sell Online Courses](https://wordpress.org/plugins/learnpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/learnpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/learnpress/)
 * [Active Topics](https://wordpress.org/support/plugin/learnpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/learnpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/learnpress/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [brianvu-tp](https://wordpress.org/support/users/briantp/)
 * Last activity: [4 years ago](https://wordpress.org/support/topic/php-function-to-enroll-user/#post-15509466)
 * Status: not resolved