• Resolved alexandrepayen

    (@alexandrepayen)


    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Justin Greer

    (@justingreerbbi)

    Awesome! Thank you for reporting this as well a providing a fix. This is the kind of stuff that makes the WP community so great.

    Thanks again and I will be sure to review and patch as soon as I can.

    Plugin Author Justin Greer

    (@justingreerbbi)

    I have pushed the update to 3.0.7 and credited you for the fix. Thanks again!

    Thread Starter alexandrepayen

    (@alexandrepayen)

    A pleasure! Keep up the good work !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘FIX : Credits being added to the Admin account’ is closed to new replies.