Created
April 25, 2022 09:53
-
-
Save nkb-bd/ca99c680ca323420d88d352bf6643f66 to your computer and use it in GitHub Desktop.
WP Fluentform quiz result filter for custom response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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