Change the way WooCommerce rounds?

I’m using an extension plugin to WooCommerce which lets me customize bulk discount prices.

With that, I need very specific pricings, like $4.23333333333 but the problem is, WooCommerce rounds, I think, two the hundreth, and ignores the rest of the value. Is there a way to change this?

Read More

I’ve tried editing woocommerce.php

            define( 'WC_ROUNDING_PRECISION', 4 );

And changing the four value to other numbers, but it doesn’t seem to change the subtotal/total.

Related posts

Leave a Reply

1 comment

  1. Under WooCommerce > Settings > General, there is an option for number of decimals.

    WooCommerce Currency Options

    Also, do not edit WooCommerce core code. Define the constant in your own site-specific snippets plugin.

    Edit

    If you only want the option to change in certain places, I think we can filter the get_option() value. As a start the following should change the option value when we’re on the cart page. But keep in mind that I haven’t tested it, so no guarantees.

    add_filter( 'pre_option_woocommerce_price_num_decimals', 'so_27236553_num_decimals' );
    function so_27236553_num_decimals( $value ){
        if( function_exists( 'is_cart' ) && is_cart() ){
            $value = 10;
        }
        return $value;
    }
    

    This is resulting in the following in the cart:

    Cart with a lot of decimals

    You might still need the precision rounding constant you originally pointed out on in your question. I’m not really sure since my price is rounded to the whole dollar.