LLMS_Student::get_enrollment_date( int $product_id, string $date = 'enrolled', string $format = null )

Get the formatted date when a user initially enrolled in a product or when they were last updated

Parameters Parameters


(int) (Required) WP Post ID of a course or membership


(string) (Optional) "enrolled" will get the most recent start date, "updated" will get the most recent status change date

Default value: 'enrolled'


(string) (Optional) date format as accepted by php date(), if none supplied uses the WP core "date_format" option

Default value: null

Top ↑

Return Return

(false|string) will return false if the user is not enrolled

Top ↑

Source Source

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

	public function get_enrollment_date( $product_id, $date = 'enrolled', $format = null ) {

		if ( ! $format ) {
			$format = get_option( 'date_format', 'M d, Y' );

		$cache_key = sprintf( 'date_%1$s_%2$s', $date, $product_id );
		$res       = $this->cache_get( $cache_key );

		if ( false === $res ) {

			$key = ( 'enrolled' === $date ) ? '_start_date' : '_status';

			global $wpdb;

			// Get the oldest recorded Enrollment date.
			$res = $wpdb->get_var(
					"SELECT updated_date FROM {$wpdb->prefix}lifterlms_user_postmeta WHERE meta_key = %s AND user_id = %d AND post_id = %d ORDER BY updated_date DESC LIMIT 1",
					array( $key, $this->get_id(), $product_id )

			$this->cache_set( $cache_key, $res );


		return ( $res ) ? date_i18n( $format, strtotime( $res ) ) : false;


Top ↑

Changelog Changelog

Version Description
3.35.0 Prepare SQL properly.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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