Okay
  Print

Hide correct answer settings in quiz itself

add this code in your wplms-customizer.php file in wplms customizer plugin : 



add_filter('bp_course_api_get_user_single_quiz_data','wplms_show_quiz_correct_answer',999,3);
function wplms_show_quiz_correct_answer($quiz_data, $request ,$user_id){ 
  $hide = get_post_meta($quiz_data['id'],'vibe_hide_answers',true);
  if(!empty($hide) && $hide=='S'){
    
      if(!empty($quiz_data['meta']['questions'])){
        foreach ($quiz_data['meta']['questions'] as $key => $q) {
          $quiz_data['meta']['questions'][$key]['show_correct_answer'] = 0;
        }
        
      }
    
  }
  return $quiz_data;
}
add_filter('wplms_course_creation_tabs','show_unit_date_time_4');
function show_unit_date_time_4($tabs){
    $setting= array();
    $setting[] = array( // Text Input
          'label' => __('Hide correct answer','wplms'), // <label>
          'desc'  => __('Date on which unit is accessible','wplms'), // description
          'id'  => 'vibe_hide_answers', // field id and name
          'type'  => 'switch', // type of field
          'from'  => 'meta',
        );
    
    foreach ($tabs['course_curriculum']['fields'] as $key => $field) {
      if($field['id'] == 'vibe_course_curriculum'){
         if(!empty($field['curriculum_elements'])){
          foreach ($field['curriculum_elements'] as $k => $elements) {
            if($elements['type']=='quiz'){
              foreach ($elements['types'] as $j => $types) {
                array_splice($tabs['course_curriculum']['fields'][$key]['curriculum_elements'][$k]['types'][$j]['fields'], (count($tabs['course_curriculum']['fields'][$key]['curriculum_elements'][$k]['types'][$j]['fields'])-1),0,$setting);
                 
              }
            }
          }
          
         } 
      }
    }
    return $tabs;
  }</label>