Automattic\WooCommerce\Admin\API\Reports\Customers

DataStore::get_customer_id_by_emailpublic staticWC 1.0

Retrieve a customer ID by email address, regardless of user registration status. Prioritizes registered customers over guest customers when both exist.

Method of the class: DataStore{}

No Hooks.

Returns

false|Int. Customer ID if found, boolean false if not.

Usage

$result = DataStore::get_customer_id_by_email( $email );
$email(string) (required)
Email address.

DataStore::get_customer_id_by_email() code WC 10.3.6

public static function get_customer_id_by_email( $email ) {
	global $wpdb;

	if ( empty( $email ) || ! is_email( $email ) ) {
		return false;
	}

	$table_name  = self::get_db_table_name();
	$customer_id = $wpdb->get_var(
		$wpdb->prepare(
			// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			"SELECT customer_id FROM {$table_name} WHERE email = %s ORDER BY user_id IS NOT NULL DESC LIMIT 1",
			$email
		)
	);

	return $customer_id ? (int) $customer_id : false;
}