Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created February 27, 2024 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrVibe/6078fcd3ebd5215c0ee90112add7ad9e to your computer and use it in GitHub Desktop.
Save MrVibe/6078fcd3ebd5215c0ee90112add7ad9e to your computer and use it in GitHub Desktop.
Exclude delay in course renewal Drip timer check
class Drip_Expired_Check{
public static $instance;
public $time_to_adjust = 0;
public static function init(){
if ( is_null( self::$instance ) )
self::$instance = new Drip_Expired_Check();
return self::$instance;
}
private function __construct(){
add_filter('bp_course_get_max_students',[$this,'expired_course'],10,3);
add_action('wplms_course_subscribed',[$this,'start_course_reset'],10,2);
add_action('wplms_course_product_puchased',[$this,'add_start_course'],10,2);
}
function add_start_course($course_id,$user_id){
$check = get_user_meta($user_id,'start_course_'.$course_id,true);
if(empty($check)){ update_user_meta($user_id,'start_course_'.$course_id,time()); }
}
function expired_course($count,$course_id,$user_id){
$existing = intval(get_user_meta($user_id,$course_id,true));
if($existing > 0 && $existing < time()){
$time_to_adjust = time() - $existing;
$this->time_to_adjust = $time_to_adjust; //cache time to adjust
}
return $count;
}
function start_course_reset($course_id,$user_id){
if($this->time_to_adjust > 0){
$check = intval(get_user_meta($user_id,'start_course_'.$course_id,true));
if($check > 0){
update_user_meta($user_id,'start_course_'.$course_id,$check+$this->time_to_adjust);
}
//extend time lost in expired & re-instating the course
}
}
}
Drip_Expired_Check::init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment