FIX : Credits being added to the Admin account
-
Hello! First of all, a quick thank you for this great plug in you developed ! It’s very helpful and I’ll come back to it if I ever need a credit system in WordPress.
I came across an odd behavior when using User Wallet Credit System.
When an order has to be confirm by the admin (using delayed methods of payment), the admin’s account gets credited instead of the user’s. This is due to your use of:
get_current_user_id()
for retrieving the account which should be credited.I slightly modified the `wpuw_add_credits_to_user_account()’ function, so that it uses the id of the customer purchasing the credits attached to the Woocommerce order, like so :
add_action( 'woocommerce_order_status_completed', 'wpuw_add_credits_to_user_account' ); function wpuw_add_credits_to_user_account ( $order_id ){ $order = new WC_Order( $order_id ); if ( count( $order->get_items() ) > 0 ){ foreach ( $order->get_items() as $item ) { $product_name = $item['name']; $product_id = $item['product_id']; $product_variation_id = $item['variation_id']; $credit_amount = floatval(get_post_meta($product_id, "_credits_amount", true)); $current_users_wallet_ballance = floatval(get_user_meta($order->get_user_id(),"_uw_balance", true)); update_user_meta($order->get_user_id(), "_uw_balance", ($credit_amount+$current_users_wallet_ballance)); } } }
Happy Coding,
Alexandre Payen
- The topic ‘FIX : Credits being added to the Admin account’ is closed to new replies.