Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Delivery Areas  >  Validate ZIP Code

apply_filters( 'vikrestaurants_validate_zip_code', bool $valid, DeliveryQuery $query, Area $area )

Fires while validating a ZIP code against the configuration of a specific delivery area.


Description

It is possible to use this hook to enhance or change the default algorithm while checking whether a specific ZIP code is allowed or not.

You can access the ZIP code of the customer by using the code below:

// extract ZIP code from search query
$zipCode = $query->getZipCode();

It is possible to access the list of configured ZIP codes through the code below:

/** @var object[] */
$codes = $area->get('codes', []);

The array contains only objects holding the following properties: from (the initial range of the ZIP code), to (the ending range) and published (whether the range should be considered or not).


Parameters

$valid

(bool)  True to immediately accept the ZIP code, false to deny the ZIP code validation., null to rely on the default algorithm.

$query

(DeliveryQuery)  The object holding the information about the address of the customer. This object is part of the E4J\VikRestaurants\DeliveryArea namespace.

$area

(Area)  The object holding the information about the configured delivery area. This object is part of the E4J\VikRestaurants\DeliveryArea namespace.


Example

/**
 * It is possible to use this hook to enhance or change the default algorithm
 * while checking whether a specific ZIP code is allowed or not.
 *
 * @param  bool           $valid  Returns true to accept the ZIP code. Return false to deny the
 *                                ZIP Code. Return null to rely on the default algorithm.
 * @param  DeliveryQuery  $query  The delivery query,
 * @param  Area           $area   The instance used to validate an address by zip code.
 *
 *
 * @since 	1.9
 */
add_filter('vikrestaurants_validate_zip_code', function($valid, $query, $area) {
    return null;
}, 10, 3);

Changelog

Version Description
1.3 Introduced.
Ultimo aggiornamento: 2023-12-28
Utile?