Support » Plugin: WordPress Payments Plugin | GetPaid » overwriting current user data

  • Resolved romannmsk

    (@romannmsk)


    good afternoon, when paying for the first invoice, a user is created in the system. in the future, if you fill out the form on behalf of the guest and indicate the already existing email of the user, but other first and last name – when the form is confirmed, the user’s data will be overwritten.

    how to prevent overwriting of user data if someone else as a guest fills out the form and indicates the email of an existing user?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Stiofan

    (@stiofansisland)

    Hi @romannmsk,

    Individual customers are linked to specific email addresses, are you sending different users invoices to the same email address?

    Thanks,

    Stiofan

    Thread Starter romannmsk

    (@romannmsk)

    The situation is as follows – there is a registered account that wants to make payments by indicating his email in the data, but on the name and surname of his relatives, and at the same time he does not want this data of relatives to be overwritten in his main account. however, he does not mind that letters will come to his mail.

    I need to understand where in the scripts the account data is being rewritten, if the system already has such a registered email.

    Plugin Contributor Brian Mutende

    (@picocodes)

    Try adding the following code to your site.

    remove_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );

    More information here https://github.com/AyeCode/invoicing/blob/9b6f2affe418e692e55994f35ce6546867e98b1e/includes/wpinv-address-functions.php#L194

    Thread Starter romannmsk

    (@romannmsk)

    thanks for the info. tried adding this line but the result didn’t change. first and last user is still updated when the guest submits the form 🙁

    https://i.imgur.com/kHBGPVQ.png

    Plugin Contributor Brian Mutende

    (@picocodes)

    Where did you add the snippet?

    Thread Starter romannmsk

    (@romannmsk)

    in my custom plugin
    also I just tried adding to the functions.php file from the template – it didn’t help

    getpaid_save_invoice_user_address updates the address, but I need to prevent updating the first name and last

    • This reply was modified 4 months, 1 week ago by romannmsk.
    • This reply was modified 4 months, 1 week ago by romannmsk.
    Plugin Contributor Brian Mutende

    (@picocodes)

    Your snippet is probably running before our hooks attach.

    Try this one instead, which updates the addresses except for the first and last name.

    add_action( 'getpaid_checkout_invoice_updated', function( $invoice ) {
        remove_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
    
        // Retrieve the invoice.
        $invoice = wpinv_get_invoice( $invoice );
    
        // Abort if it does not exist.
        if ( empty( $invoice ) || $invoice->is_renewal() ) {
            return;
        }
    
        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
    
            if ( $field == 'first_name' || $field == 'last_name' ) {
                continue;
            }
    
            if ( is_callable( array( $invoice, "get_$field" ) ) ) {
                $value = call_user_func( array( $invoice, "get_$field" ) );
    
                // Only save if it is not empty.
                if ( ! empty( $value ) ) {
                    update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
                }
    
            }
    
        }
    
    }, 5 );
    Thread Starter romannmsk

    (@romannmsk)

    thanks for your advice!

    at the beginning I tried adding this snippet to a custom plugin – it didn’t work.

    then added function.php from the template to the file – it did not work either.

    after I added a “stop” to the loop process and this is what was found – when the first_name field is found, the script stops, and if you go to the admin panel and see the user data, they will already be new (changed).

        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
    		var_dump($field);
    		die();
            if ( $field == 'first_name' || $field == 'last_name' ) {
                continue;
            }

    maybe some of the function changes the data earlier?

    even if you comment out all this function and its call and then submit the form, the name data will be updated

    • This reply was modified 4 months, 1 week ago by romannmsk.
    Plugin Contributor Brian Mutende

    (@picocodes)

    This function stops the default address from being updated. It does not stop the address of the invoice being paid from being updated. If that’s what you’re trying to achieve then you can remove the first name and last name fields from the payment form so as not to collect them.

    Plugin Contributor Brian Mutende

    (@picocodes)

    You can also add the snippet to your site then ask the client to pay and use his relatives’ first and last names. The invoice will use the new name but the default name saved to his account won’t change.

    Thread Starter romannmsk

    (@romannmsk)

    Thanks a lot, the problem was solved! 🙂

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.