• Hi!

    I found a bug in woocommerce checkout.
    If you set the numbers of decimals to zero on the dashboard, all trailing zeros will be trimmed.

    When plugin store the items, it store it in pure decimal format, without any formatting. When show it for you, it uses the woocommerce_price function.

    Let’s check this woocommerce_format_decimal function in woocommerce-core-functions.php

    function woocommerce_format_decimal( $number ) {
        return rtrim( rtrim( number_format( (float) $number, get_option( 'woocommerce_price_num_decimals' ), '.', '' ), '0' ), '.' );
    }

    Ok, what we have here?

    This is in case, if we did set the numbers of decimals to 0.
    first, woocommerce formating the number to decimal.
    for example, if we have a price: 8,900.00 then the most inner function number format will turn it into this:

    string '8900' (length=4)

    And this is bad, because after this, it rtrim the trailing ‘.’ char, and after the zeros.

    So this is why we will get 89 for the price of the product.

    Because we are on the deadline, now i have no time to fix it. If someone do it, please post here the fixed code, or maybe later, when i will have time, i’ll do it.

Viewing 1 replies (of 1 total)
  • I found a quick fix add this to your option page.

    update_option( 'woocommerce_price_trim_zeros', 'no' );

    This worked for me.

Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce price bug’ is closed to new replies.