Title: Enroll with code
Last modified: November 29, 2022

---

# Enroll with code

 *  Resolved [wpuzman](https://wordpress.org/support/users/wpuzman/)
 * (@wpuzman)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/enroll-with-code/)
 * Hello. How can i enroll a user to a course with php? You described here: [https://wordpress.org/support/topic/php-function-to-enroll-user/](https://wordpress.org/support/topic/php-function-to-enroll-user/)
 * But i want to add user_id as manually. Not auto with learn_press_get_current_user()
   function.
 * Any function like this? learn_press_enroll_user( $user_id, $course_id )
 * Thanks in advance.

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

 *  Plugin Support [brianvu-tp](https://wordpress.org/support/users/briantp/)
 * (@briantp)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/enroll-with-code/#post-16246306)
 * Hi,
 * You don’t need to use the code, You can go to LearnPress -> Order -> Create a
   new order for the user, select the course you need and set the status is completed-
   > Save.
 * Thanks
 *  Plugin Author [ThimPress](https://wordpress.org/support/users/thimpress/)
 * (@thimpress)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/enroll-with-code/#post-16252137)
 * Hi,
 * You can use below code example. Direct use is not recommended if you have no 
   control over the use case. You must read and understand the code to be able to
   use it. If not will be make LP run wrong logic.
 *     ```
       $user_item_data = [
        'user_id' => $user_id,
        'item_id' => $course_id
        'start_time' => time();
        'status'       = LP_COURSE_ENROLLED;
        'graduation'   = LP_COURSE_GRADUATION_IN_PROGRESS;
       ];
       $user_item_new_or_update = new LP_User_Item_Course( $user_item_data );
       $result = $user_item_new_or_update->update();
       ```
   
 * Read more code on the “handle_item_order_completed” method.
 * Thanks.

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

The topic ‘Enroll with code’ 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
 * 3 participants
 * Last reply from: [ThimPress](https://wordpress.org/support/users/thimpress/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/enroll-with-code/#post-16252137)
 * Status: resolved