You appear to be a bot. Output may be restricted
Description
Usage
EDD_Batch_Payments_Import::set_customer( $row );
Parameters
- $row
- ( mixed ) required –
Returns
void
Source
File name: easy-digital-downloads/includes/admin/import/class-batch-import-payments.php
Lines:
1 to 100 of 112
private function set_customer( $row ) { global $wpdb; $customer = false; $customer = false; $email = ''; if( ! empty( $this->field_mapping['email'] ) && ! empty( $row[ $this->field_mapping['email'] ] ) ) { $email = sanitize_text_field( $row[ $this->field_mapping['email'] ] ); } // Look for a customer from the canonical source, if any if( ! empty( $this->field_mapping['edd_customer_id'] ) && ! empty( $row[ $this->field_mapping['edd_customer_id'] ] ) ) { $canonical_id = absint( $row[ $this->field_mapping['edd_customer_id'] ] ); $mapped_id = $wpdb->get_var( $wpdb->prepare( "SELECT edd_customer_id FROM $wpdb->edd_customermeta WHERE meta_key = '_canonical_import_id' AND meta_value = %d LIMIT 1", $canonical_id ) ); } if( ! empty( $mapped_id ) ) { $customer = new EDD_Customer( $mapped_id ); } if( empty( $mapped_id ) || ! $customer->id > 0 ) { // Look for a customer based on provided ID, if any if ( ! empty( $this->field_mapping['edd_customer_id'] ) && ! empty( $row[ $this->field_mapping['edd_customer_id'] ] ) ) { $customer_id = absint( $row[ $this->field_mapping['edd_customer_id'] ] ); $customer_by_id = new EDD_Customer( $customer_id ); } // Now look for a customer based on provided email if( ! empty( $email ) ) { $customer_by_email = new EDD_Customer( $email ); } // 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_email ) && ( empty( $customer_by_id ) || $customer_by_id->id !== $customer_by_email->id ) ) { $customer = $customer_by_email; } elseif ( ! empty( $customer_by_id ) ) { $customer = $customer_by_id; if( ! empty( $email ) ) { $customer->add_email( $email ); } } // Make sure we found a customer. Create one if not. if ( empty( $customer->id ) ) { if ( ! $customer instanceof EDD_Customer ) { $customer = new EDD_Customer(); } } if ( ! empty( $this->field_mapping['name'] ) && ! empty( $row[ $this->field_mapping['name'] ] ) ) { $name = $row[ $this->field_mapping['name'] ]; } else { $first_name = ''; $last_name = ''; if ( ! empty( $this->field_mapping['first_name'] ) && ! empty( $row[ $this->field_mapping['first_name'] ] ) ) { $first_name = $row[ $this->field_mapping['first_name'] ]; } if ( ! empty( $this->field_mapping['last_name'] ) && ! empty( $row[ $this->field_mapping['last_name'] ] ) ) { $last_name = $row[ $this->field_mapping['last_name'] ]; } $name = $first_name . ' ' . $last_name; } $customer->create( array( 'name' => sanitize_text_field( $name ), 'email' => empty( $email ) ? '' : $email, ) ); if( ! empty( $canonical_id ) && (int) $canonical_id !== (int) $customer->id ) {