Skip to content

Instantly share code, notes, and snippets.

@codersaiful
Created June 4, 2024 11:36
Show Gist options
  • Save codersaiful/b658a89aee29de9c9757ec84ebde7da2 to your computer and use it in GitHub Desktop.
Save codersaiful/b658a89aee29de9c9757ec84ebde7da2 to your computer and use it in GitHub Desktop.
<?php
function my_custom_footer_script() {
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var inputBox = $('input.input-text.qty.text.wcmmq-qty-input-box.input-text.qty');
inputBox.attr('type','number');
inputBox.attr('inputmode','numeric');
$(document.body).on('change','input.input-text.qty.text.wcmmq-qty-input-box.input-text.qty',function(){
var thisInputBox = $(this);
var min = $(this).attr('min');
min = parseInt(min);
var max = $(this).attr('max');
var val = $(this).val();
val = parseInt(val);
if( typeof max !== 'undefined' && max != '' && val > max){
thisInputBox.val(max).trigger('click');
}
if( typeof min !== 'undefined' && min != '' && val < min){
thisInputBox.val(min).trigger('click');
}
});
inputBox.each(function(){
});
});
</script>
<?php
}
add_action('wp_footer', 'my_custom_footer_script');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment