Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double customer/user attachment on purchase with different email … #3890

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions includes/payments/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ function edd_insert_payment( $payment_data = array() ) {

// Create or update a customer
$customer = new EDD_Customer( $payment_data['user_email'] );

// If we didn't find a customer and the user is logged in, check by user_id #3881
if ( empty( $customer->id ) && is_user_logged_in() ) {
$customer = new EDD_customer( get_current_user_id(), true );
}

$customer_data = array(
'name' => $payment_data['user_info']['first_name'] . ' ' . $payment_data['user_info']['last_name'],
'email' => $payment_data['user_email'],
Expand All @@ -183,13 +189,6 @@ function edd_insert_payment( $payment_data = array() ) {

if ( empty( $customer->id ) ) {
$customer->create( $customer_data );
} else {
// Only update the customer if their name or email has changed
if ( $customer_data['email'] !== $customer->email || $customer_data['name'] !== $customer->name ) {
// We shouldn't be updating the User ID here, that is an admin task
unset( $customer_data['user_id'] );
$customer->update( $customer_data );
}
}

$customer->attach_payment( $payment, false );
Expand Down