Italian (Italy)
Knowledge Base  >  Vik Booking  >  Per Programmatori  >  Coupon Codes validation

apply_filters( 'vikbooking_validate_coupon_code', bool $valid, array &$coupon )

Fires during the validation for the submitted coupon code.


Description

This filter can be used to apply additional validations to the submitted coupon code, or to manipulate the coupon record at runtime.

When this hook is triggered, the system already validated the standard conditions and the coupon has been approved for the usage.

In case of positive result, the customer will be allowed to redeem the specified coupon code.


Parameters

$valid

(bool)  Use false to deny the coupon usage.

$coupon

(array)  An associative array for the coupon record.


Example

The example below shows how to implement a custom coupon code validation according to any possible needs, hence the logged in WordPress user and its capabilities/role.

/**
 * Filters the validation of the submitted coupon code, which passed the
 * internal validation already. Use this hook to implement a custom coupon
 * validation, and eventually to manipulate the coupon record values.
 * 
 * @param  bool   $valid   true if the coupon is valid, false otherwise.
 * @param  array  $coupon  the coupon record array (passed by reference).
 */
add_filter('vikbooking_validate_coupon_code', function($valid, &$coupon)
{
    if ($valid === false) {
        return false;
    }

    // perform any kind of validation/manipulation here

    return true;
}, 10, 2);

Changelog

Version Description
1.6.7 Introduced.

Ultimo aggiornamento: 2024-01-17
Utile?
100% delle persone lo ha trovato utile.