Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active July 27, 2026 07:36
Show Gist options
  • Select an option

  • Save andrewlimaza/34983b1f319bc41516e7eab3d9409480 to your computer and use it in GitHub Desktop.

Select an option

Save andrewlimaza/34983b1f319bc41516e7eab3d9409480 to your computer and use it in GitHub Desktop.
PMPro groengraag.nl - Level 5 checkout: single-click submit button + change wording
<?php
/**
* PMPro - groengraag.nl
* Levels 5 (Groene Try-Out) & 6 (De groene maand) only: prevent the submit
* button being clicked more than once, and change its wording while the form
* submits.
*
* Classic [pmpro_checkout] shortcode. Does NOT disable the <input>, so the
* `submit-checkout` value is still POSTed and checkout completes normally.
*
* Add via Code Snippets plugin or a PMPro Customizations include.
*/
function ggraag_checkout_single_submit_trial() {
if ( ! function_exists( 'pmpro_is_checkout' ) || ! pmpro_is_checkout() ) {
return;
}
// Resolve the level being checked out (handles discount codes / level overrides).
if ( ! function_exists( 'pmpro_getLevelAtCheckout' ) ) {
return;
}
$target_levels = array( 5, 6 ); // Groene Try-Out, De groene maand.
$level = pmpro_getLevelAtCheckout();
if ( empty( $level->id ) || ! in_array( (int) $level->id, $target_levels, true ) ) {
return;
}
?>
<script>
document.addEventListener('DOMContentLoaded', function () {
var form = document.querySelector('form.pmpro_form, form[name="checkout"], #pmpro_form');
if (!form) { return; }
var submitting = false;
var busyText = 'Even geduld, we maken alles voor je klaar…';
form.addEventListener('submit', function (e) {
if (submitting) {
e.preventDefault(); // Block every click after the first.
return false;
}
submitting = true;
var btns = form.querySelectorAll(
'input[name="submit-checkout"], input[type="submit"], button[type="submit"], .pmpro_btn-submit-checkout'
);
btns.forEach(function (btn) {
if (btn.tagName === 'INPUT') { btn.value = busyText; }
else { btn.textContent = busyText; }
// Visually disable WITHOUT removing it from the POST.
btn.style.pointerEvents = 'none';
btn.style.opacity = '0.6';
btn.setAttribute('aria-disabled', 'true');
});
}, true);
});
</script>
<?php
}
add_action( 'wp_footer', 'ggraag_checkout_single_submit_trial' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment