Bug in the total cart price variable (leads to free shipping malfunction)
-
Hi, I’m really surprised to find such a great plugin, thank you! During setting it up I’ve found out that the free shipping limit wasn’t working (shipping price was always 0). The problem lies in the wrong value of $cart_price. Preg_replace() in the plugin code (see below) always appends some additional digits to the end of the variable, so it outputs an extremely high number.
EXAMPLE:
Price received from WC get_cart_total(): “550 Kč” (Czech currency)
$cart_price value after preg_replace: “55075269” (The additional digits “75269” are always the same – They correspond to the decimal values of unicode characters “K” and “č”.)PLUGIN CODE:
$cart_price = preg_replace( '#[^\d.,]#', '', $woocommerce->cart->get_cart_total() );
MY SOLUTION:
I’ve replaced the code by another way of receiving the cart total (inspired by https://stackoverflow.com/questions/30063173/woocommerce-get-cart-total-as-number):if ( WC()->cart->prices_include_tax ) { $cart_price = $woocommerce->cart->get_cart_contents_total() + $woocommerce->cart->get_cart_contents_tax(); } else { $cart_price = $woocommerce->cart->get_cart_contents_total(); }
- The topic ‘Bug in the total cart price variable (leads to free shipping malfunction)’ is closed to new replies.