• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors
  • My Account

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI

Code Reference

Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Classes / LLMS_Controller_Account / LLMS_Controller_Account::cancel_subscription()

LLMS_Controller_Account::cancel_subscription()

Lets student cancel recurring access plan subscriptions from the student dashboard view order screen

Contents

  • Return
  • Source
  • Related
    • Uses
  • Changelog
  • User Contributed Notes

Return #Return

(void)


Top ↑

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


Top ↑

Related #Related

Uses #Uses

Uses
Uses Description
includes/forms/controllers/class.llms.controller.account.php: llms_subscription_cancelled_by_student

Action triggered after a recurring subscription is cancelled from the student dashboard by the student.

includes/llms.functions.core.php: llms_verify_nonce()

Verify nonce with additional checks to confirm request method

includes/llms.functions.core.php: llms_get_post()

Retrieve the LLMS Post Model for a give post by ID or WP_Post Object

includes/functions/llms-functions-wrappers.php: llms_filter_input()

Gets a specific external variable by name and optionally filters it

includes/functions/llms.functions.notice.php: llms_add_notice()

Stores notice in llms_notices session


Top ↑

Changelog #Changelog

Changelog
Version Description
3.35.0 Sanitize $_POST data.
3.19.0 Unknown.
3.10.0 Introduced.

Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

© 2014 - 2023 LifterLMS · Privacy Policy · Terms and Conditions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.