Skip to content

Instantly share code, notes, and snippets.

@rynaldos-zz
Created April 17, 2020 06:22
Show Gist options
  • Save rynaldos-zz/f14ccdc98bffeaf3c9748b16c9a389b3 to your computer and use it in GitHub Desktop.
Save rynaldos-zz/f14ccdc98bffeaf3c9748b16c9a389b3 to your computer and use it in GitHub Desktop.
WooCommerce min/max quantities translate browser message
function wc_max_qty_scripts() {
wp_add_inline_script( 'woocommerce', 'window.onload = function(){
function onBlurHandler( event ) {
var max = this.getAttribute( "max" );
if ( this.validity.rangeOverflow ) {
message = this.value + " is too much! Please contact us to order more than " + max + ".";
this.setCustomValidity( message );
} else {
this.setCustomValidity("");
}
}
var quantity = document.querySelector( "form.cart .qty" );
var cartQuantity = document.querySelector( "form.woocommerce-cart-form .qty" );
if ( quantity ) {
quantity.addEventListener( "blur", onBlurHandler, false );
}
if ( cartQuantity ) {
cartQuantity.addEventListener( "blur", onBlurHandler, false );
}
};'
);
}
add_action( 'wp_enqueue_scripts', 'wc_max_qty_scripts', 9999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment