Force Course expiry for all users to a set date and time

This tutorial is show us how you can control the end date for all the users purchasing the course.

Note this tutorial only valid for course purchases via WooCommerce.

Add this code in Child theme functions.php or WPLMS Customizer – wplms_customizer.php

1. Add control in admin panel for Course end date.

add_filter('wplms_course_metabox','wplms_set_course_end_date');
 
function wplms_set_course_end_date($metabox){
    $metabox[]=array( // Text Input
            'label' => __('Course End Date','vibe-customtypes'), // <label>
            'desc'  => __('Date from which Course Ends','vibe-customtypes'), // description
            'id'    => 'vibe_end_date', // field id and name
            'type'  => 'date', // type of field
        );
    return $metabox;
}

Result :

 

2. Set Course expiry to set date :

add_action('wplms_course_product_puchased','wplms_set_course_expiry',10,2);
function wplms_set_course_expiry($course_id,$user_id){
    $end_date = get_post_meta($course_id,'vibe_end_date',true);
        if(isset($end_date) && $end_date){
        $timestamp = strtotime($end_date);
        update_user_meta($user_id,$course_id,$timestamp);
    }
}