LLMS_Student::get_enrollment_order( int $product_id )
Retrieve the order which enrolled a student in a given course or membership.
Description Description
Retrieves the most recently updated order for the given product.
Parameters Parameters
- $product_id
-
(int) (Required) WP Post ID of the LifterLMS Product (course, lesson, or membership)
Return Return
(LLMS_Order|false) Instance of the LLMS_Order or false if none found
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_type' => 'llms_order', ) ); if ( $q->have_posts() ) { return new LLMS_Order( $q->posts[0] ); } // Couldn't find an order, return false. return false;
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.7.0 | Replaced the call to the deprecated LLMS_Lesson::get_parent_course() method with LLMS_Lesson::get( 'parent_course' ) . |
3.0.0 | Introduced. |