Learndash: Customize user enroll time

we use the learndash LMS and want to let users get access to lessons everyday at 6am with enrollment based access. For this purpose the LMS stores the enrollment time of every user in the db usermeta table in UNIX. So my question is: How can i change this value to the same date the user enrolled just so the time is 8am but the day stays the same? And how can i run this function shortly after the user enrolled?

Thx

Topic timestamp php Wordpress

Category Web


Learndash wrote me with a filter:

/**
* LearnDash Lesson Access From
*
* This filter is called when using the learndash lesson drip feed options. This filter allows override timestamp value.
*
* @since 2.4
*
* @param int $gmt_timestamps This is a GMT timestamp value like 1489062972
* @param int $lesson_id The Lesson post ID.
* @param int $user_id The User ID. This is the user_id value passed to the calling function. It may not be the current user
*
* @return int adjusted value for $gmt_timestamp
*/
add_filter( 'ld_lesson_access_from__visible_after', function ( $gmt_timestamp = 0, $lesson_id = 0, $user_id = 0 ) {

// Check to ensure our timestamp is not empty
if ( !empty( $gmt_timestamp ) ) {

// Example 1: In this example we want to remove hh:mm:ss: values from the timestamp so the user gets access at midnight.
// Let's assume for the purpose of this example you have a lesson using the 'Make lesson visible X days after sign-up' option with a value
// if '1'. A student started the course on 2017-02-18 02:34pm. This would mean with the '1' value they will get access to the lesson one
// day (24 hours) later on 2017-02-19 02:34pm.
// But assume you don't want the user to have to wait 24 hours. You want the user do get access at the start of the next day 2017-02-19 (midnight)

// The logic below is how this can be done.

// Then convert to YMD format.
$gmt_ymd = date('Y-m-d H:i:s', $gmt_timestamp );

// At this point $gmt_ymd is still GMT so we need to adjust it to our local timezone. To do
// we use the WP utility function get_date_from_gmt(). But instead of converting the
// hour/minute/seconds to local we want to set these to 00:00:00 so the time is midnight
$gmt_local_midnight = get_date_from_gmt( $gmt_ymd, 'Y-m-d 00:00:00' );


// so noy we have a nice human readable value in $gmt_local_midnight
// that will be something like '2017-02-15 00:00:00'.


// We now need to return a timestamp (not YMD) back to LD. So we need to convert the YMD
// date back into a timestamp
$gmt_timestamp = learndash_get_timestamp_from_date_string( $gmt_local_midnight, true );
}


// Always return the $gmt_timestamp.
return $gmt_timestamp;


}, 10, 3);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.