WC_API_Customers::get_customer_by_email()publicWC 2.1

Get the customer for the given email

Method of the class: WC_API_Customers{}

No Hooks.

Return

Array|WP_Error.

Usage

$WC_API_Customers = new WC_API_Customers();
$WC_API_Customers->get_customer_by_email( $email, $fields );
$email(string) (required)
the customer email
$fields(array)
-
Default: null

Changelog

Since 2.1 Introduced.

WC_API_Customers::get_customer_by_email() code WC 8.7.0

public function get_customer_by_email( $email, $fields = null ) {
	try {
		if ( is_email( $email ) ) {
			$customer = get_user_by( 'email', $email );
			if ( ! is_object( $customer ) ) {
				throw new WC_API_Exception( 'woocommerce_api_invalid_customer_email', __( 'Invalid customer email', 'woocommerce' ), 404 );
			}
		} else {
			throw new WC_API_Exception( 'woocommerce_api_invalid_customer_email', __( 'Invalid customer email', 'woocommerce' ), 404 );
		}

		return $this->get_customer( $customer->ID, $fields );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}