Hi mubasher99,
the easiest way to have a “play again” button is to include a link (or button shortcode if your theme uses one) in the results field that simply links back to the quiz page. The page will refresh and the user can retake the quiz.
As for changing the formatting of the results… that’s a bit harder, but still doable. There are two ways to do this. The first is to edit includes/js/hdq_script.js and taking a look at line 147 hdq_calculate_total(), but I’d recommend waiting a few days since I’ll be releasing the new version of HD Quiz then.
The new version includes a hook on quiz completion allowing you to add your own functions once the quiz has been submitted. Using this, you’ll be able to add the following code to your theme’s functions.php file.
The following is just an example but once the new version is up, this should work for you.
function hdq_submit($quizOptions){
$quizOptions->hdq_submit = "hdq_custom_submit";
return $quizOptions;
}
add_action( 'hdq_submit', 'hdq_submit' );
// the above tells HD Quiz to look for a function called hdq_custom_submit and to fire it off. It will then also try and send data to admin-ajax, but we won't be using that part.
function hdq_before_test($quizID){
?>
<script>
function hdq_custom_submit(){
let data = {};
// hdq_score is array of score (score/total questions)
let c = hdq_score[0];
let t = hdq_score[1];
let p = (parseFloat(c) / parseFloat(t)) * 100;
p = p.toFixed(2);
let d = '<p>Total correct answers= <strong>'+c+'</strong><br/>
Total Wrong Answers= <strong>'+t+'</strong><br/>
Total percentage= <strong>'+p+'</strong><br/>%</p>';
jQuery(".hdq_results_inner .hdq_result").html(d);
return JSON.stringify(data); // expects a json string to be returned
}
</script>
<?php
}
add_action( 'hdq_before', 'hdq_before_test' );
// the above allows us to add any code to HD Quiz before the quiz. This can be any HTML, PHP, JS, whatever! We are using it to add a custom JS function