Automattic\WooCommerce\StoreApi\Utilities

OrderController::validate_email()protectedWC 1.0

Validates the customer email. This is a required field.

Метод класса: OrderController{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->validate_email( $order );
$order(\WC_Order) (обязательный)
Order object.

Код OrderController::validate_email() WC 8.7.0

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
		);
	}
}