Calculate and round prices to 2 digits
-
Hello,
I would WC to calculate all prices rounded by 2 digits, not by 6 (default or more).
Case: I have regular and B2B price shop in one. The default setting is that shop is price includes taxes, howerver in B2B it doesn’t include taxes. Therefore, I have a product with regular price & taxes 29,99e, and 19,16e without (19% DE VAT). If I add 12 items it calculates – 19.957999€ * 12 = 239.495800e -> 239.50e, which is actually accurate but I need something else for the end-client.I want that if the price is displayed in cart 19,16e and add quantity 12 = 19,16 x 12 = 239,52e. 2 cents difference. Same applies to EVERYTHING else in cart => discounts, fees, shipping, subtotal, total.
Shortly, if the single price is rounded by 2 digits, then all other calculations are rounded by 2 as well, instead of the super précised calculation (6). What you see is what you get ??
I tried://add_filter('raw_woocommerce_price', 'round_price_product', 1000, 1); add_filter('woocommerce_product_get_price', 'round_price_product', 1000, 1); add_filter('woocommerce_product_get_regular_price', 'round_price_product', 1000, 1); add_filter('woocommerce_product_variation_get_price', 'round_price_product', 1000, 1); add_filter('woocommerce_product_variation_get_regular_price', 'round_price_product', 1000, 1); add_filter('woocommerce_get_price_excluding_tax', 'round_price_product', 1000, 1); add_filter('woocommerce_get_price_including_tax', 'round_price_product', 1000, 1); //add_filter('woocommerce_tax_round', 'round_price_product', 1000, 1); function round_price_product($price) { // Return rounded price return round($price, 2); }
I also tried to modify the main WC_ROUNDING_PRECISION but obviously it won’t work.
The only way I found which is very bad IMO is to manipulate the cart manually by calculating every single line via woocommerce_cart_product_subtotal and woocommerce_after_calculate_totals. However, I prefer a more elegant way if possible.
- The topic ‘Calculate and round prices to 2 digits’ is closed to new replies.