• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_Batch_Payments_Import::set_customer() –

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 ) {
[1] [2] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 14th September 2022

Primary Sidebar

Information

Function name: EDD_Batch_Payments_Import::set_customer
Class ref: EDD_Batch_Payments_Import
Plugin ref: Easy Digital Downloads
Version: 3.1.0.2
Sourcefile: includes/admin/import/class-batch-import-payments.php
File ref: includes/admin/import/class-batch-import-payments.php
Deprecated?: No
API Letters: B,E,I,P,S

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 6.2.2
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins