English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Coupon  >  Before Activate

apply_filters( 'vikrestaurants_before_activate_coupon', bool $activate, object $couponarray $args )

Fires while checking whether the specified coupon code can be redeemed or not.


Description

This filter can be used to apply additional conditions to the coupon validation.

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

$activate

(bool)  Use false to deny the coupon usage.

$coupon

(object)  An object containing the details of the coupon code.

$args

(array)  A configuration array, which may contain different attributes according to the section (restaurant or take-away). Here's a list of supported attributes:

  • date - the current date and time for restaurant reservations, the check-in date and time for take-away orders. The date is always formatted in UNIX timestamp;
  • total - the total number of guests for restaurant reservations, the total cost of the items in cart for take-away orders;
  • group - "0" when we are booking restaurant reservations, "1" when we are completing take-away orders.

Example

The example below accepts the activation of a specific coupon code only in case the check-in is between Monday and Thursday.

/**
 * This filter can be used to apply additional conditions to the 
 * coupon validation. When this hook is triggered, the
 * system already validated the standard conditions and the
 * coupon has been approved for the usage.
 *
 * @param  boolean  $activate  Use false to deny the coupon code activation.
 * @param  object   $coupon    The restaurant reservation to check.
 * @param  array    $args      A configuration array.
 */
add_filter('vikrestaurants_before_activate_coupon', function($activate, $coupon, $args)
{
    // make sure we are checking the targeted coupon code
    if ($coupon->code == 'ABCD1234')
    {
        // get day of the week
        $w = (int) date('w', $args['date']);

        // check if the day of the week is Fri (5), Sat (6) or Sun (0)
        if (in_array($w, [0, 5, 6]))
        {
            // prevent coupon activation
            $activate = false;
        }
    }

    return $activate;
}, 10, 3);

Changelog

Version Description
1.0 Introduced.
Last Update: 2021-07-28
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information