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

Bypass user verification when importing payments #8692

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 24 additions & 13 deletions includes/admin/import/class-batch-import-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public function init() {
'zip' => '',
'country' => '',
);

remove_action( 'edd_customer_post_attach_payment', 'edd_connect_guest_customer_to_existing_user', 10, 4 );
}

/**
Expand Down Expand Up @@ -393,7 +395,8 @@ private function set_customer( $row ) {

global $wpdb;

if( ! empty( $this->field_mapping['email'] ) && ! empty( $row[ $this->field_mapping['email'] ] ) ) {
$email = false;
if ( ! empty( $this->field_mapping['email'] ) && ! empty( $row[ $this->field_mapping['email'] ] ) ) {

$email = sanitize_text_field( $row[ $this->field_mapping['email'] ] );

Expand All @@ -407,13 +410,16 @@ private function set_customer( $row ) {

}

$customer = false;
if( ! empty( $mapped_id ) ) {

$customer = new EDD_Customer( $mapped_id );

}

if( empty( $mapped_id ) || ! $customer->id > 0 ) {
$customer_by_id = false;
$customer_by_email = false;
if ( empty( $mapped_id ) || ! $customer->id > 0 ) {

// Look for a customer based on provided ID, if any

Expand All @@ -434,26 +440,24 @@ private function set_customer( $row ) {
}

// Now compare customer records. If they don't match, customer_id will be stored in meta and we will use the customer that matches the email

if( ( empty( $customer_by_id ) || $customer_by_id->id !== $customer_by_email->id ) && ! empty( $customer_by_email ) ) {
if ( ! empty( $customer_by_email ) && ( empty( $customer_by_id ) || ( $customer_by_id->id !== $customer_by_email->id ) ) ) {

$customer = $customer_by_email;

} else if ( ! empty( $customer_by_id ) ) {
} elseif ( ! empty( $customer_by_id ) ) {

$customer = $customer_by_id;

if( ! empty( $email ) ) {
if ( $customer && ! empty( $email ) ) {
$customer->add_email( $email );
}

}

// Make sure we found a customer. Create one if not.
if( empty( $customer->id ) ) {
if ( empty( $customer->id ) ) {

if ( ! $customer instanceof EDD_Customer ) {
$customer = new EDD_Customer;
$customer = new EDD_Customer();
}

$first_name = '';
Expand Down Expand Up @@ -481,12 +485,19 @@ private function set_customer( $row ) {
}

}


}

if( $email && $email != $customer->email ) {
$customer->add_email( $email );
if ( $email ) {
if ( $email !== $customer->email ) {
$customer->add_email( $email );
}

if ( empty( $customer->user_id ) ) {
$user = get_user_by( 'email', $email );
if ( $user ) {
$customer->update( array( 'user_id' => $user->ID ) );
}
}
}

return $customer->id;
Expand Down