Skip to content

Instantly share code, notes, and snippets.

@nkb-bd
Created April 25, 2022 09:53
Show Gist options
  • Select an option

  • Save nkb-bd/ca99c680ca323420d88d352bf6643f66 to your computer and use it in GitHub Desktop.

Select an option

Save nkb-bd/ca99c680ca323420d88d352bf6643f66 to your computer and use it in GitHub Desktop.
WP Fluentform quiz result filter for custom response
add_filter('fluentform_quiz_score_value', function ($result, $formId, $scoreType, $quizResults){
$targetId = 154; // change your form ID
if($formId != $targetId){
return $result;
}
if($scoreType == 'percent'){
$score = 0;
$totalPoints = 0;
foreach ($quizResults as $result) {
$totalPoints += $result['points'];
if ($result['correct'] == true) {
$score += $result['points'];
}
}
$result = number_format((($score / $totalPoints) * 100), 2) . '%';
}
return $result;
},10,4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment