Please follow the below instructions for course end date functionality:
1. WP Admin -> Plugins -> Editor -> WPLMS Customizer -> classes -> customizer_class.php
2. Add the following code in the _construct function :
PHP Code:
add_filter('wplms_course_metabox',array($this,'wplms_custom_course_meta')); add_filter('wplms_course_details_widget',array($this,'wplms_custom_course_details_widget')); add_filter('wplms_take_course_page',array($this,'wplms_custom_take_course_page'),10,2); add_filter('wplms_course_product_id',array($this,'wplms_custom_take_course_page'),10,2); add_action('wplms_course_before_front_main',array($this,'wplms_custom_course_before_main')); add_action('wplms_course_subscribed',array($this,'set_expiry_end_date'),10,2); add_filter('wplms_course_creation_tabs',array($this,'switch_wplms_front_end_tabs123'),1);
3. Add the following code in class :
PHP Code:
function wplms_custom_course_meta($course_meta){ $prefix = 'vibe_'; $course_meta[]=array( // Text Input 'label' => __('Course End Date','vibe-customtypes'), // <label> 'desc' => __('Date from which Course End','vibe-customtypes'), // description 'id' => $prefix.'end_date', // field id and name 'type' => 'date', // type of field ); return $course_meta; } function wplms_custom_course_details_widget($details){ $course_id = get_the_ID(); $end_date=get_post_meta($course_id,'vibe_end_date',true); if(isset($end_date) && $end_date!=''){ $end_date= date_i18n( get_option( 'date_format' ),strtotime($end_date)); $extra = array('end_date'=>'<li><i>'.$end_date.'</i>End Date</li>'); array_splice($details, 1,0,$extra); } return $details; } function wplms_custom_take_course_page($link, $course_id){ $end_date=get_post_meta($course_id,'vibe_end_date',true); if(isset($end_date) && $end_date!='' && strtotime($end_date) < time()){ return '?error=end_date'; } return $link; } function wplms_custom_course_before_main(){ $error = $_REQUEST['error']; if(isset($error) && $end_date!='' && $error == 'end_date'){ echo '<div id="message" class="notice"><p>Course ended !</p></div>'; } } function set_expiry_end_date($course_id,$user_id){ $end_date=get_post_meta($course_id,'vibe_end_date',true); $existing_time=get_user_meta($user_id,$course_id,true); $offset = get_option('gmt_offset'); $end_date = strtotime( $end_date); $end_date = $end_date + ($offset * 3600); $effectove_time = $end_date; if(!empty( $end_date) && time()< $effectove_time){ update_user_meta($user_id,$course_id,$effectove_time); } } function switch_wplms_front_end_tabs123($settings){ $fields = $settings['course_settings']['fields']; $arr=array(array( // Text Input 'label' => __('Course End Date','vibe-customtypes'), // <label> 'desc' => __('Date from which Course End','vibe-customtypes'), // description 'id' => 'vibe_end_date', // field id and name 'type' => 'date', // type of field )); array_splice($fields, (count($fields)-1), 0,$arr ); $settings['course_settings']['fields'] = $fields; return $settings; }
Please check screenshot for reference: