Automattic\WooCommerce\StoreApi\Schemas\V1

BillingAddressSchema::validate_callback()publicWC 1.0

Validate the given address object.

Method of the class: BillingAddressSchema{}

No Hooks.

Return

true|\WP_Error.

Usage

$BillingAddressSchema = new BillingAddressSchema();
$BillingAddressSchema->validate_callback( $address, $request, $param );
$address(array) (required)
Value being validated.
$request(\WP_REST_Request) (required)
The Request.
$param(string) (required)
The param being validated.

BillingAddressSchema::validate_callback() code WC 9.0.1

public function validate_callback( $address, $request, $param ) {
	$errors  = parent::validate_callback( $address, $request, $param );
	$address = (array) $address;
	$errors  = is_wp_error( $errors ) ? $errors : new \WP_Error();

	if ( ! empty( $address['email'] ) && ! is_email( $address['email'] ) ) {
		$errors->add(
			'invalid_email',
			__( 'The provided email address is not valid', 'woocommerce' )
		);
	}

	return $errors->has_errors( $errors ) ? $errors : true;
}