Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created February 13, 2017 14:39
Show Gist options
  • Select an option

  • Save strangerstudios/1dba674e942c34d49edde4bd2473430d to your computer and use it in GitHub Desktop.

Select an option

Save strangerstudios/1dba674e942c34d49edde4bd2473430d to your computer and use it in GitHub Desktop.
Add a .5s delay every time the checkout PMPro checkout button is clicked.
/*
Add a .5s delay every time the checkout PMPro checkout button is clicked.
This is meant to prevent automated scripts from testing your checkout page repeatedly.
We will likely update this script to keep track on the server side as well to account for cases
where the script reloads the entire page with every attempt.
*/
function enqueue_scripts_slowdown_checkout() {
?>
<script>
function my_disablePMProCheckoutButtons() {
jQuery('.pmpro_btn-submit-checkout,.pmpro_btn-submit').attr('disabled', 'disabled');
jQuery('#pmpro_processing_message').html('Please wait...');
jQuery('#pmpro_processing_message').css('visibility', 'visible');
//jQuery('#pmpro_processing_message').show();
}
function my_enablePMProCheckoutButtons() {
jQuery('.pmpro_btn-submit-checkout,.pmpro_btn-submit').removeAttr("disabled");
//jQuery('#pmpro_processing_message').hide();
jQuery('#pmpro_processing_message').css('visibility', 'hidden');
jQuery('#pmpro_processing_message').html('Processing...');
}
var nsubmits = 1;
var disablecheckout = false;
jQuery(document).ready(function() {
jQuery(".pmpro_form").submit(function(event) {
//every time the checkout button is clicked add a 1s delay
nsubmits++;
//disable checkout now
disablecheckout = true;
//reenable checkout after nsubmits seconds
setTimeout(function(){ console.log(nsubmits); disablecheckout = false; }, nsubmits*500);
});
//make sure submit stays disabled if we want it to
setInterval(function() {
console.log(disablecheckout);
if(disablecheckout)
my_disablePMProCheckoutButtons();
else
my_enablePMProCheckoutButtons();
}, 500);
});
</script>
<?php
}
add_action('wp_footer', 'enqueue_scripts_slowdown_checkout', 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment