• cartpauj

    (@cartpauj)


    I’m trying to enroll a student programmatically when a payment occurs from a 3rd party service.

    I dug through the code quite a bit and this is what I’ve come up with. Can you please tell me if there’s a better/easier or more correct way?

        $course_id = 31;
        $user = learn_press_get_user($obj->user_id, false);
    
        $item = array(
          'order_item_name' => 'ADHD Course',
          'item_id' => $course_id,
          'quantity' => 1,
          'subtotal' => $obj->amount,
          'total' => $obj->total
        );
        
        $order = learn_press_create_order();
        $order->set_customer_note( '' );
        $order->set_status( 'lp-completed' );
        $order->set_total( $obj->total );
        $order->set_subtotal( $obj->amount );
        $order->set_user_ip_address( learn_press_get_ip() );
        $order->set_user_agent( learn_press_get_user_agent() );
        $order->set_created_via( 'external' );
        $order->set_user_id( $obj->user_id );
        $order->save();
        $order->add_item( $item );
        
        $user->enroll($course_id, $order->id);
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Ken Nguyen

    (@kendy73)

    Hi cartpauj,

    I’m discussing with our team about your case ??

    Regards,

    Ken

    Ken, could you please help me with a similar problem? There’s a whole month I contact Learnpress Support, and they didn’t help me yet. I losing money. I can’t create orders from my website backend. Every time I click on create order, and try changing client or course, don’t work. The only thing that happens, is the order code that turn into another number, but nothing happens.

    Plugin Contributor Ken Nguyen

    (@kendy73)

    Hi scarllettlins,

    Sorry to hear that. I will need to check your site more carefully. You can email me to [email protected] with subject “scarllettlins – LearnPress Support”.

    Hi LearnPress team,

    Looks like this is still not resolved yet right?

    Thanks,
    Bryan.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Programmatically Enroll Student’ is closed to new replies.