Mandatory Course review before course finish !

Add following code in Child theme – functions.php

http://prntscr.com/mjwmfa

`

add_filter('bp_get_course_check_course_complete_stop',function($flag,$course_id,$user_id){
  //Check for unit completion
  $course_curriculum=bp_course_get_curriculum_units($id);
  if(isset($course_curriculum) && count($course_curriculum)){
    $flag =0;
  foreach($course_curriculum as $unit_id){
  //if(is_numeric($unit_id)){
    $unittaken = bp_course_check_unit_complete($unit_id,$user_id,$id);
    if(empty($unittaken) && bp_course_get_post_type($unit_id) == 'quiz'){
      $unittaken=get_user_meta($user_id,$unit_id,true);
    }
    if(!isset($unittaken) || !$unittaken){
      $flag=$unit_id;
      break;
    }
  //}
  }

  $flag = apply_filters('wplms_finish_course_check',$flag,$course_curriculum);

  if($flag){

    $type=bp_course_get_post_type($flag);
    switch($type){
    case 'unit':
    $type= __('UNIT','vibe');
    break;
    case 'assignment':
    $type= __('ASSIGNMENT','vibe');
    break;
    case 'quiz':
    $type= __('QUIZ','vibe');
    break;
    }//Default for other customized options
    $message = __('PLEASE COMPLETE THE ','vibe').$type.' : '.get_the_title($flag);
    echo '<div class="message"><p>'.apply_filters('wplms_unfinished_unit_quiz_message',$message,$flag).'</p></div>';

    return 1;

    }

  }

  $args = array(
  'user_id' => $user_id,
  'number' => 1, // how many comments to retrieve
  'post_id' =>$course_id
  );

  $comments = get_comments( $args );
  if(!$comments){
  echo '<div class="message">

  Post a review to finish the course !
  </div>';
  ?>
  <div class="course_reviews">
  <?php
  comments_template('/course-review.php',true);
  ?>
  </div>
  <?php
  return 1;
  }
  return $flag;
},10,3);

 

Leave a Reply

Your email address will not be published. Required fields are marked *