Take the 2-minute tour ×

I'm basically creating a points based system for woocommerce in WordPress. This is based on usermeta that is added manually. (the idea being, people recycle products to gain points, then use points to purchase products on a seperate woocommerce that shares the user data).

I have created a checkout that disables if not enough points, or adds up the amount the user will have left after purchasing products (possibly slightly vunerable at this stage but besides the point).

THE PROBLEM i'm having is updating the user meta after the purchase has been made. i.e every user has a box called 'Points' in their user table that only admins can see - this needs to be updated with a new formula of (Current Points - Order total). Heres the code i came up with not sure how to implement this or whether this will actually work.. i planted this in the 'thankyou page' which occurs after an order has been 'placed'


        $user_id = wp_get_current_user();
        $pointsafterorder = $current_user->points - $woocommerce->cart->total;

        // will return false if the previous value is the same as $new_value
        update_user_meta( $user_id, $current_user->points, $pointsafterorder );


If anyone has a fix, questions or any thoughts please let me know.

Thanks Rich

share|improve this question
you should first try your solution on your own and if that doesn't work ask about the specific problem you are using. questions of type is this code good should go to codereview.stackexchange.com –  Nitzan Volman Jul 31 '13 at 13:15
Hi, i have tried this solution (the code on the question), and it's not working - sorry if i wasn't specific enough to point that out. –  rico roughnecks Jul 31 '13 at 14:43

1 Answer 1

up vote 1 down vote accepted

The code you have isnt getting the user id.

First you need to query the current user like what you have:

 $current_user = wp_get_current_user();

But the bit you are missing is:

 echo $current_user->ID;

So your code adpated will look like this:

$current_user = wp_get_current_user();
update_user_meta( $current_user->ID, $current_user->points, $pointsafterorder );
share|improve this answer

Your Answer


