The details
Currently when using wc_format_decimal , different results were returning, creating inconsistency with backward compatibility.
To keep the result of wc_format_decimal consistent, empty strings are now returned as empty strings instead of being coerced to decimals, regardless of the precision provided. Previously wc_format_decimal( '', 0 ) would return 0 but now returns an empty string to keep consistent with wc_format_decimal( '', false ).
How can I tell if this affects me?
You may be affected if your plugin uses wc_format_decimal with an empty string as its $number value and passes a decimal point precision as a second argument.
What action should I take?
If your plugin has conditional checks that expect wc_format_decimal( '', 0 ) to return a 0 value, you require an update to your plugin code by the WooCommerce 10.4.0 release. You can either provide integer values to wc_format_decimal or you can update your logic to compare against an empty string.
The soft deprecation begins in WooCommerce 10.3.0, and will be officially shipped in 10.4.0.
// Always pass a number instead of a string.
$number = $value === '' ? 0 : $value;
wc_format_decimal( $value, 0 );
// Check the result for an empty string.
$result = wc_format_decimal( '', 0 );
if ( $result === '' ) {
// Do something if an empty string was used.
}
Leave a Reply