LLMS_Student::get_enrollment_order( int $product_id )

Retrieve the order which enrolled a student in a given course or membership Retrieves the most recently updated order for the given product


Description Description


Parameters Parameters

$product_id

(int) (Required) WP Post ID of the LifterLMS Product (course, lesson, or membership)


Top ↑

Return Return

(obj|false) Instance of the LLMS_Order or false if none found


Top ↑

Source Source

File: includes/models/model.llms.student.php

	public function get_enrollment_order( $product_id ) {

		// if a lesson id was passed in, cascade up to the course for order retrieval
		if ( 'lesson' === get_post_type( $product_id ) ) {
			$lesson = new LLMS_Lesson( $product_id );
			$product_id = $lesson->get_parent_course();
		}

		// attempt to locate the order via the enrollment trigger
		$trigger = $this->get_enrollment_trigger( $product_id );
		if ( strpos( $trigger, 'order_' ) !== false ) {

			$id = str_replace( array( 'order_', 'wc_' ), '', $trigger );
			if ( is_numeric( $id ) ) {
				if ( 'llms_order' === get_post_type( $id ) ) {
					return new LLMS_Order( $id );
				} else {

					return get_post( $id );
				}
			}
		}

		// couldn't find via enrollment trigger, do a WP_Query
		$q = new WP_Query( array(
			'order' => 'DESC',
			'orderby' => 'modified',
			'meta_query' => array(
				'relation' => 'AND',
				array(
					'key' => '_llms_user_id',
					'value' => $this->get_id(),
				),
				array(
					'key' => '_llms_product_id',
					'value' => $product_id,
				),
			),
			'posts_per_page' => 1,
			// 'post_status' => $statuses,
			'post_type' => 'llms_order',
		) );

		if ( $q->have_posts() ) {
			return new LLMS_Order( $q->posts[0] );
		}

		// couldn't find an order, return false
		return false;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: