LLMS_Controller_Orders::on_user_enrollment_deleted( int $user_id, int $product_id, string $trigger )

Called when an user enrollment is deleted.


Description Description

Will set the related order status to ‘cancelled’.


Top ↑

Parameters Parameters

$user_id

(int) (Required) WP User ID.

$product_id

(int) (Required) WP Post ID of the course or membership.

$trigger

(string) (Required) The deleted enrollment trigger, or 'any' if no specific trigger.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/controllers/class.llms.controller.orders.php

	public function on_user_enrollment_deleted( $user_id, $product_id, $trigger ) {

		$order_id = 'order_' === substr( $trigger, 0, 6 ) ? absint( substr( $trigger, 6 ) ) : false;
		$order    = $order_id ? llms_get_post( $order_id ) : false;

		if ( $order && is_a( $order, 'LLMS_Order' ) ) {

			// No need to run an unenrollment as we're reacting to an enrollment deletion, user enrollments data already removed.
			add_filter( 'llms_unenroll_on_error_order', '__return_false', 100 );
			$order->set_status( 'cancelled' );
			// Reset unenrollment's suspension..
			remove_filter( 'llms_unenroll_on_error_order', '__return_false', 100 );

		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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