Browse: Home / Snippets /

Change course expiration date for specific user

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

/**
 * Example usage for ld_course_access_expires_on filter. - Change course expiration date for a specific user
 * Please keep in mind that the user might need to be re enrolled manually in the course.
 */
add_filter(
    'ld_course_access_expires_on',
    function( $course_access_upto, $course_id, $user_id ) {
        //Change $course_id = 240 and $user_id = 4 by the corresponding user id and course id.
        if ( ( ! empty( $course_id ) ) && ( $course_id == 240 ) && ( $user_id == 4 ) ) {
            //Change expiration date
            $course_access_upto = strtotime('2020-11-30');	
        }

        // Always return $course_access_upto.
        return $course_access_upto;
    },
    10,
    3
);