Skip to content

Instantly share code, notes, and snippets.

@pavr0m
Last active March 12, 2020 13:52
Show Gist options
  • Save pavr0m/a20015e123711ccb851443e1fc7c96ff to your computer and use it in GitHub Desktop.
Save pavr0m/a20015e123711ccb851443e1fc7c96ff to your computer and use it in GitHub Desktop.
WooCommerce. Checkout form - prevent submit on Enter key pressed.
<?php
add_action( 'wp_footer', 'woo_prevent_submit_on_keypress' );
function woo_prevent_submit_on_keypress() {
ob_start();?>
<script>
jQuery(function($){
$('form.woocommerce-checkout input').keydown(function (e) {
if (e. keyCode == 13) {
e.preventDefault();
var tab = $(e.target).attr("tabindex") + 1;
$("input[tabindex=" + tab + "]").focus();
return false;
}
});
});
</script>
<?php
ob_end_flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment