Ad

How Do I Remove The Extra 1 Cent In Woocommerce Checkout?

- 1 answer

I am having an issue whereby woocommerce add 1 cent extra on top of my stacked discount.

So my price is $100. I give 2 unique coupon with discount value of 10% each. Tax is 10% What happen is I expect user to pay $88. But eventually, there is an additional 0.01 cent.

I tried looking for solution here, but there don't seem to have any conclusion. The issue keeps resurfacing. So is there any way I can manipulate the price? Like after calculate total, how do I change the price before it reaches payment gateway?

Here is the link to the reported issues: https://github.com/woocommerce/woocommerce/issues/20997

Ad

Answer

I do not know where the problem comes from. But you can use this solution.

You can round the product price using Woocommerce filter.

Copy this code in functions.php in your child theme:

add_filter('woocommerce_product_get_price', 'round_woocommrce_price', 99, 2);
add_filter('woocommerce_get_variation_regular_price', 'round_woocommrce_price', 99);
add_filter('woocommerce_get_variation_price', 'round_woocommrce_price', 99);
add_filter('raw_woocommerce_price', 'round_woocommrce_price' );
function round_woocommrce_price($price, $product = NULL) {
    // you can return this, if you are interested: floor($price) + 0.99
    return floor($price);
}
Ad
source: stackoverflow.com
Ad