@@ -82,7 +82,6 @@ public function __construct() {
8282
8383 // Expire access plans.
8484 add_action ( 'llms_access_plan_expiration ' , array ( $ this , 'expire_access ' ), 10 , 1 );
85-
8685 }
8786
8887 /**
@@ -122,8 +121,17 @@ public function complete_order( $order, $old_status ) {
122121 */
123122 do_action ( 'lifterlms_order_complete ' , $ order_id ); // @todo used by AffiliateWP only, can remove after updating AffiliateWP.
124123
125- // Enroll student.
126- llms_enroll_student ( $ user_id , $ product_id , 'order_ ' . $ order_id );
124+ /**
125+ * Filter whether the user should be automatically enrolled when the order completes.
126+ *
127+ * @since 9.1.2
128+ *
129+ * @param bool Whether to enroll the student. Defaults to true.
130+ * @param LLMS_Order $order The order.
131+ */
132+ if ( apply_filters ( 'lifterlms_enroll_student_on_order_complete ' , true , $ order ) ) {
133+ llms_enroll_student ( $ user_id , $ product_id , 'order_ ' . $ order_id );
134+ }
127135
128136 // Trigger purchase action, used by engagements.
129137
@@ -153,7 +161,6 @@ public function complete_order( $order, $old_status ) {
153161
154162 // Maybe schedule a payment.
155163 $ order ->maybe_schedule_payment ();
156-
157164 }
158165
159166 /**
@@ -210,7 +217,6 @@ public function error_order( $order ) {
210217 }
211218
212219 llms_unenroll_student ( $ order ->get ( 'user_id ' ), $ order ->get ( 'product_id ' ), $ status , 'order_ ' . $ order ->get ( 'id ' ) );
213-
214220 }
215221
216222 /**
@@ -229,7 +235,6 @@ public function on_delete_order( $post_id ) {
229235 if ( $ order && is_a ( $ order , 'LLMS_Order ' ) ) {
230236 llms_delete_student_enrollment ( $ order ->get ( 'user_id ' ), $ order ->get ( 'product_id ' ), 'order_ ' . $ order ->get ( 'id ' ) );
231237 }
232-
233238 }
234239
235240 /**
@@ -258,7 +263,6 @@ public function on_user_enrollment_deleted( $user_id, $product_id, $trigger ) {
258263 remove_filter ( 'llms_unenroll_on_error_order ' , '__return_false ' , 100 );
259264
260265 }
261-
262266 }
263267
264268 /**
@@ -325,7 +329,6 @@ public function expire_access( $order_id ) {
325329 if ( $ new_order_status ) {
326330 $ order ->set_status ( $ new_order_status );
327331 }
328-
329332 }
330333
331334 /**
@@ -343,7 +346,6 @@ public function pending_cancel_order( $order ) {
343346
344347 $ order ->unschedule_recurring_payment ();
345348 $ order ->maybe_schedule_expiration ();
346-
347349 }
348350
349351 /**
@@ -511,7 +513,6 @@ public function recurring_charge( $order_id ) {
511513 // Passed validation, hand off to the gateway.
512514 $ gateway ->handle_recurring_transaction ( $ order );
513515 return true ;
514-
515516 }
516517
517518 /**
@@ -546,7 +547,6 @@ public function set_untrash_status( $new_status, $post_id, $previous_status ) {
546547 }
547548
548549 return $ new_status ;
549-
550550 }
551551
552552 /**
@@ -576,7 +576,6 @@ public function transaction_failed( $txn ) {
576576 $ order ->set ( 'status ' , 'llms-failed ' );
577577
578578 }
579-
580579 }
581580
582581 /**
@@ -596,7 +595,6 @@ public function transaction_refunded( $txn ) {
596595 return ; }
597596
598597 $ order ->set ( 'status ' , 'llms-refunded ' );
599-
600598 }
601599
602600 /**
@@ -625,7 +623,6 @@ public function transaction_succeeded( $txn ) {
625623
626624 // Maybe schedule a payment.
627625 $ order ->maybe_schedule_payment ();
628-
629626 }
630627
631628 /**
@@ -691,7 +688,6 @@ public function transition_status( $new_status, $old_status, $post ) {
691688 * @param string $new_status The new order or transaction status.
692689 */
693690 do_action ( "lifterlms_ {$ post_type }_status_ {$ new_status }" , $ obj , $ old_status , $ new_status );
694-
695691 }
696692
697693 /**
@@ -734,7 +730,6 @@ private function validate_selected_gateway( $gateway_id, $plan ) {
734730 }
735731
736732 return $ gateway ;
737-
738733 }
739734
740735 /**
@@ -804,7 +799,6 @@ public function switch_payment_source() {
804799 _deprecated_function ( __METHOD__ , '7.0.0 ' , 'LLMS_Controller_Checkout::switch_payment_source ' );
805800 LLMS_Controller_Checkout::instance ()->switch_payment_source ();
806801 }
807-
808802}
809803
810804return new LLMS_Controller_Orders ();
0 commit comments