Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamarazuk/aea31e6bc4fe96e190046bf6dd710df0 to your computer and use it in GitHub Desktop.
Save tamarazuk/aea31e6bc4fe96e190046bf6dd710df0 to your computer and use it in GitHub Desktop.
WooCommerce Measurement Price Calculator: Redefine the quantity input's pattern to include floating point values to fix the "Please match the requested format" HTML validation error that occurs with the Enfold theme. Please review our guide for adding custom code to WordPress Sites here: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
<?php // only copy this line if needed
/**
* Filter the quantity input's pattern attribute to fix the "Please
* match the requested format" HTML validation error that occurs when using
* WooCommerce Measurement Price Calculator with certain premium themes
*
* @props to mensmaximus {@link https://github.com/mensmaximus} for the
* proposed solution
*
* @param string $pattern the value of the input element's pattern attribute
* @return string the updated pattern to allow floats
*/
function sv_wc_mpc_fix_quantity_input_pattern_premium_themes( $pattern ) {
if ( has_filter( 'woocommerce_stock_amount', 'floatval' ) ) {
$pattern = '^\d*(\.\d*)?$';
}
return $pattern;
}
add_filter( 'woocommerce_quantity_input_pattern', 'sv_wc_mpc_fix_quantity_input_pattern_premium_themes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment