Skip to main content
deleted 1 characters in body
Source Link
souporserious
  • 679
  • 1
  • 11
  • 27
function oe_charge_customer( $customer ) { 
    
    // load the stripe libraries
    require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
    
    // check if in test mode or not
    check_stripe_api();
    
    // counter
    $i = $customer['i'];
    
    // get user meta, if any
    $payment_args = get_user_meta( $customer['user_id'], 'oe_customer_details' );
    
    // update paid value to true
    $payment_args[0]['payments'][$i]['paid'] = $i;1;

    // attempt to charge the customer's card
    try {
    
        $charge = Stripe_Charge::create(array(
                'amount'    => $customer['amount'] * 100,
                'currency'  => 'usd',
                'customer'  => $customer['cust_id']
            )
        );
        
        // update user profile to show paid
        update_user_meta( $customer['user_id'], 'oe_customer_details', $payment_args );
    
    } catch (Exception $e) {
    
        wp_die($e);
    
    }
    
}
function oe_charge_customer( $customer ) { 
    
    // load the stripe libraries
    require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
    
    // check if in test mode or not
    check_stripe_api();
    
    // counter
    $i = $customer['i'];
    
    // get user meta, if any
    $payment_args = get_user_meta( $customer['user_id'], 'oe_customer_details' );
    
    // update paid value to true
    $payment_args[0]['payments'][$i]['paid'] = $i;

    // attempt to charge the customer's card
    try {
    
        $charge = Stripe_Charge::create(array(
                'amount'    => $customer['amount'] * 100,
                'currency'  => 'usd',
                'customer'  => $customer['cust_id']
            )
        );
        
        // update user profile to show paid
        update_user_meta( $customer['user_id'], 'oe_customer_details', $payment_args );
    
    } catch (Exception $e) {
    
        wp_die($e);
    
    }
    
}
function oe_charge_customer( $customer ) { 
    
    // load the stripe libraries
    require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
    
    // check if in test mode or not
    check_stripe_api();
    
    // counter
    $i = $customer['i'];
    
    // get user meta, if any
    $payment_args = get_user_meta( $customer['user_id'], 'oe_customer_details' );
    
    // update paid value to true
    $payment_args[0]['payments'][$i]['paid'] = 1;

    // attempt to charge the customer's card
    try {
    
        $charge = Stripe_Charge::create(array(
                'amount'    => $customer['amount'] * 100,
                'currency'  => 'usd',
                'customer'  => $customer['cust_id']
            )
        );
        
        // update user profile to show paid
        update_user_meta( $customer['user_id'], 'oe_customer_details', $payment_args );
    
    } catch (Exception $e) {
    
        wp_die($e);
    
    }
    
}
Source Link
souporserious
  • 679
  • 1
  • 11
  • 27

Updating wordpress user meta data array (unexpected multiple arrays)

So I am trying to update a user meta data array that I have previously stored with this function:

function oe_charge_customer( $customer ) { 
    
    // load the stripe libraries
    require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');
    
    // check if in test mode or not
    check_stripe_api();
    
    // counter
    $i = $customer['i'];
    
    // get user meta, if any
    $payment_args = get_user_meta( $customer['user_id'], 'oe_customer_details' );
    
    // update paid value to true
    $payment_args[0]['payments'][$i]['paid'] = $i;

    // attempt to charge the customer's card
    try {
    
        $charge = Stripe_Charge::create(array(
                'amount'    => $customer['amount'] * 100,
                'currency'  => 'usd',
                'customer'  => $customer['cust_id']
            )
        );
        
        // update user profile to show paid
        update_user_meta( $customer['user_id'], 'oe_customer_details', $payment_args );
    
    } catch (Exception $e) {
    
        wp_die($e);
    
    }
    
}

I am getting somewhat expected results, except it keeps throwing it in a new array every time it gets updated. Any idea why this is happening? I can't seem to wrap my head around it . I get the following after it gets updated:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [0] => Array
                                (
                                    [0] => Array
                                        (
                                            [customer] => Array
                                                (
                                                    [name] => 
                                                    [id] => cus_2Oo1hyvYyZsaj0
                                                    [user_id] => 18
                                                )

                                            [payments] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [amount] => 16
                                                            [date] => 1376710188
                                                            [paid] => 0
                                                        )

                                                    [1] => Array
                                                        (
                                                            [amount] => 4
                                                            [date] => 1376710238
                                                            [paid] => 0
                                                        )

                                                )

                                        )

                                    [payments] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [paid] => 0
                                                )

                                        )

                                )

                        )

                    [payments] => Array
                        (
                            [1] => Array
                                (
                                    [paid] => 1
                                )

                        )

                )

        )

)