Last active
July 1, 2020 03:59
-
-
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/
This file contains hidden or 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
<?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