LLMS_Controller_Account::cancel_subscription()
Lets student cancel recurring access plan subscriptions from the student dashboard view order screen
Return Return
(void)
Source Source
File: includes/forms/controllers/class.llms.controller.account.php
public function cancel_subscription() {
// Invalid nonce or the form wasn't submitted.
if ( ! llms_verify_nonce( '_cancel_sub_nonce', 'llms_cancel_subscription', 'POST' ) ) {
return;
} elseif ( empty( $_POST['order_id'] ) ) {
return llms_add_notice( __( 'Something went wrong. Please try again.', 'lifterlms' ), 'error' );
}
$order = llms_get_post( llms_filter_input( INPUT_POST, 'order_id', FILTER_SANITIZE_NUMBER_INT ) );
$uid = get_current_user_id();
if ( ! $order || $uid != $order->get( 'user_id' ) ) {
return llms_add_notice( __( 'Something went wrong. Please try again.', 'lifterlms' ), 'error' );
}
$note = __( 'Subscription cancelled by student from account page.', 'lifterlms' );
// Active subscriptions move to pending-cancel.
// All other statuses are cancelled immediately.
if ( 'llms-active' === $order->get( 'status' ) ) {
$new_status = 'pending-cancel';
$note .= ' ' . __( 'Enrollment will be cancelled at the end of the prepaid period.', 'lifterlms' );
} else {
$new_status = 'cancelled';
}
$order->set_status( $new_status );
$order->add_note( $note );
/**
* Action triggered after a recurring subscription is cancelled from the student dashboard by the student.
*
* @since 3.17.8
*
* @param LLMS_Order $order The order object.
* @param integer $uid The WP_User ID the student who cancelled the subscription.
*/
do_action( 'llms_subscription_cancelled_by_student', $order, $uid );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.35.0 | Sanitize $_POST data. |
| 3.19.0 | Unknown. |
| 3.10.0 | Introduced. |