Automattic\WooCommerce\StoreApi\Utilities

OrderController::validate_email()protectedWC 1.0

Validates the customer email. This is a required field.

Method of the class: OrderController{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_email( $order );
$order(\WC_Order) (required)
Order object.

OrderController::validate_email() code WC 9.4.2

protected function validate_email( \WC_Order $order ) {
	$email = $order->get_billing_email();

	if ( empty( $email ) ) {
		throw new RouteException(
			'woocommerce_rest_missing_email_address',
			__( 'A valid email address is required', 'woocommerce' ),
			400
		);
	}

	if ( ! is_email( $email ) ) {
		throw new RouteException(
			'woocommerce_rest_invalid_email_address',
			sprintf(
				/* translators: %s provided email. */
				__( 'The provided email address (%s) is not valid—please provide a valid email address', 'woocommerce' ),
				esc_html( $email )
			),
			400
		);
	}
}