Created
April 17, 2020 06:22
-
-
Save rynaldos-zz/f14ccdc98bffeaf3c9748b16c9a389b3 to your computer and use it in GitHub Desktop.
WooCommerce min/max quantities translate browser message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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