• Hello there,

    I would like to show in the my account page for the users the total amount of money spent in all orders. For that I use the woocommerce function wc_get_customer_total_spent and insert it in the my-orders.php file like this:
    <?php echo wc_get_customer_total_spent( get_current_user_id() );?>

    The problem is that the amount returned is wrong, the decimals are not summed up and only show the decimals from the last order. Example:

    A user have to orders, first total 10.35$ and second 10.11$ the function returns 20.11$. I have tested in many users and always the same issue, it only shows the decimals from the last order not summing up any of the previous decimals.

    Is anyone finding the same issue?.

    Thanks.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Look in the database, postmeta table, at _order_total for the orders of this user. Are they stored are decimals or with commas?

    Thread Starter ferdipm72

    (@ferdipm72)

    Thanks for the feedback Mike, on the postmeta I have just checked the orders are stored with decimal point. My woocommerce settings are with decimal comma. Well I thought this might be the reason but it isn’t, I change woo commerce to decimal point and the same behaviour.

    The function do a select sum to get the totals, I was thinking that maybe some db configuration should be changed? or maybe some extra function to convert on the fly inside the function?. But this would be to touch woocomerce core function…

    Plugin Contributor Mike Jolley

    (@mikejolley)

    SUM() should work fine if they are stored with . decimals. Did you try a manual SQL query to check SUM works as intended?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wc_get_customer_total_spent issue’ is closed to new replies.