Free shipping – incorrect calculation
-
The problem is in the file \includes\shipping\free-shipping\class-wc-shipping-free-shipping.php on line 200
if ( $total >= $this->min_amount ) {
Comparison (float) >= (string)
In the above case, e.g. 150>=75 but 150>=’75’ is treated as (string)>=(string). This has further consequences. For purchases of $8-9.99 it will allow for free shipping.I have a problem with PHP 8.1.27 CGI/FastCGI, WordPress 6.4.3, WooCommerce 8.7.0
As a temporary solution without changing plugin file, I added the following code to my theme:
add_filter(‘woocommerce_shipping_free_shipping_instance_option’, function($val, $key){
if($key!=’min_amount’)return $val;
return Automattic\WooCommerce\Utilities\NumberUtil::round($val, wc_get_price_decimals());
}, 10, 2);After additional analysis, I discovered that when the min_amount field is 150, everything works fine. If the min_amount is 150,00, there is a problem. I can remove the “,00” from the value and once saved, it counts fine. When I open the free shipping edition and have previously saved 150, it show 150,00 in the field and if it is saved in this format, there is a problem with the calculations.
- The topic ‘Free shipping – incorrect calculation’ is closed to new replies.