From 3423889962cf420011abc7615072b8491b3d990f Mon Sep 17 00:00:00 2001 From: Chris Klosowski Date: Tue, 6 Oct 2015 10:07:23 -0700 Subject: [PATCH] Fix douple customer/user attachment on purchase with different email #3881 --- includes/payments/functions.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/includes/payments/functions.php b/includes/payments/functions.php index e511c0e4588..24400cf6099 100755 --- a/includes/payments/functions.php +++ b/includes/payments/functions.php @@ -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'], @@ -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 );