Wordpress update user meta through woocommerce checkout process -


i'm creating points based system woocommerce in wordpress. based on usermeta added manually. (the idea being, people recycle products gain points, use points purchase products on seperate woocommerce shares user data).

i have created checkout disables if not enough points, or adds amount user have left after purchasing products (possibly vunerable @ stage besides point).

the problem i'm having updating user meta after purchase has been made. i.e every user has box called 'points' in user table admins can see - needs updated new formula of (current points - order total). heres code came not sure how implement or whether work.. planted in 'thankyou page' occurs after order has been 'placed'

        <?php           $user_id = wp_get_current_user();         $pointsafterorder = $current_user->points - $woocommerce->cart->total;          // return false if previous value same $new_value         update_user_meta( $user_id, $current_user->points, $pointsafterorder );           ?> 

if has fix, questions or thoughts please let me know.

thanks rich

the code have isnt getting user id.

first need query current user have:

 $current_user = wp_get_current_user(); 

but bit missing is:

 echo $current_user->id; 

so code adpated this:

$current_user = wp_get_current_user(); $pointsafterorder = $current_user->points - $woocommerce->cart->total; update_user_meta( $current_user->id, $current_user->points, $pointsafterorder ); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -