English (United Kingdom)
Knowledge Base  >  Vik Booking  >  For Developers  >  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.

Last Update: 2024-01-17
Helpful?
100% of people found this helpful.

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.