LLMS_Controller_Orders::expire_access( int $order_id )
Handle expiration & cancellation from a course / membership.
Description Description
Called via scheduled action set during order completion for plans with a limited access plan.
Additionally called when an order is marked as "pending-cancel" to revoke access at the end of a pre-paid period.
Parameters Parameters
- $order_id
-
(int) (Required) WP_Post ID of the LLMS Order.
Return Return
(void)
Source Source
File: includes/controllers/class.llms.controller.orders.php
public function expire_access( $order_id ) {
$order = new LLMS_Order( $order_id );
$new_order_status = false;
// Pending cancel order moves to cancelled.
if ( 'llms-pending-cancel' === $order->get( 'status' ) ) {
$status = 'cancelled'; // Enrollment status.
$note = __( 'Student unenrolled at the end of access period due to subscription cancellation.', 'lifterlms' );
$new_order_status = 'cancelled';
// All others move to expired.
} else {
$status = 'expired'; // Enrollment status.
$note = __( 'Student unenrolled due to automatic access plan expiration', 'lifterlms' );
}
/**
* Filters whether or not recurring payments should be stopped on access plan expiration.
*
* By default when an access plan expires, recurring payments are stopped.
*
* @since 7.5.0
*
* @param bool
* @param LLMS_Order $order Instance of the order.
* @param mixed $new_order_status New order status. If `false` it means that the new order status is not
* going to change. At this stage the orders status is not changed yet.
* @param string $enrollment_status The new enrollment status. At this stage the enrollment status is not changed yet.
*/
$unschedule_recurring_payment = apply_filters(
'llms_unschedule_recurring_payment_on_access_plan_expiration',
true,
$order,
$new_order_status,
$status
);
llms_unenroll_student( $order->get( 'user_id' ), $order->get( 'product_id' ), $status, 'order_' . $order->get( 'id' ) );
$order->add_note( $note );
if ( $unschedule_recurring_payment ) {
$order->unschedule_recurring_payment();
}
if ( $new_order_status ) {
$order->set_status( $new_order_status );
}
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.5.0 | Potentially allow recurring payment to go ahead even if access plans expired. |
| 3.19.0 | Unknown. |
| 3.0.0 | Introduced. |