• Resolved mikemfsg

    (@mikemfsg)


    I’m having a small issue using the store credit feature. Clients are able to check out normally if they have enough credit to cover the entire order, but if they have less store credit than the total at checkout and attempt to enter the remaining amount of credit they have, sometimes they will get an alert that they are entering an invalid amount.

    The strange thing is if they decrease the amount of credit they want to use by $0.01 it applies properly. This looks like some kind of issue with how the system is rounding or not rounding store credit values at checkout.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Fauzan Azizie

    (@fauzanade)

    Hi @mikemfsg,

    Could you please provide me with some samples on how to replicate this issue? I tried applying the Store Credit with decimal value with less than the order value and it works fine for me. https://snipboard.io/psotcQ.jpg

    Hello,

    To replicate this issue is not that easy.
    You must have added and removed store credits to an user to finally get this issue.
    As a matter of fact, the following sequence did the trick for me:
    From a brand new client, with no store credit: +5.01, +5, -10.01, +4.99, +0.02, +0.03, +5.03, -0.6 .
    This way, user gets 9.47 store credits.

    In this case, the user can’t redeem 9.47 credits. But 9.46 is ok, so is 9.469…
    That is because of float limitations (read this).
    I did some debug and here is the results I got: screenshot of notification.
    You can see there that $amount - $balance equals MINUS ZERO dot zero (-0.000000), and not just ZERO (0.000000). This demonstrates that $amount is considered greater than $balance… On the contrary, $balance - $amount equals 0.000000 !

    Knowing that, the best I could achieve seems to be changing this line into : if ($amount < 0 || round($amount, 2) > round($balance, 2) ) { as exposed in https://www.php.net/manual/en/language.types.float.php .

    Hope it helps.

    • This reply was modified 2 years, 11 months ago by madmax4ever.
    • This reply was modified 2 years, 11 months ago by madmax4ever.

    Note that this may solve the “wrong” notification issue by allowing the user to set the good amount, but it will note solve other undergoing calculation precision issues.

    Plugin Support Fauzan Azizie

    (@fauzanade)

    Hi @madmax4ever,

    Thanks for your further explanation.

    I’ve raised this to our dev team to fix in the upcoming update of Advanced Coupons for WooCommerce plugin. ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Rounding issue with store credit’ is closed to new replies.