WC_API_Customers::get_customer_by_email() public WC 2.1
Get the customer for the given email
{} It's a 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)
- -
Changelog
Since 2.1 | Introduced. |
Code of WC_API_Customers::get_customer_by_email() WC API Customers::get customer by email WC 5.0.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() ) );
}
}