Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  System  >  Generate Serial Code

apply_filters_ref_array( 'vikappointments_generate_serial_code', bool $status, string &$code, array &$map, int $length, mixed $scope )

Fires while generating a serial code.


Description

A serial code is a random alphanumeric string that can be used for different purposes. Just to be clear, the Order Key column of the appointments is a serial code. This hook can be used to change the way the system generates a serial code.

It is possible to edit the code or simply to alter the map of allowed tokens. In case the serial code didn't reach the specified length, the remaining characters will be generated according to the default algorithm.

By default the method generates a serial code containing only uppercase characters and digits.


Parameters

$status

(bool)  True on success, false otherwise.

&$code

(string)  The current serial code. Since the argument is passed by reference, it is possible to manipulate the serial code.

&$map

(array)  Either a linear or a multi-dimensional array containing the allowed tokens.

$length

(int)  The requested length of the serial code.

$scope

(string|null)  The purpose of the serial code (the entity that requested the code generation).
Here's a list of supported scopes.

  • coupon - the default random code used for the creation of a coupon;
  • cron-key - the secure key to dispatch the cron jobs;
  • appointment-confkey - the confirmation key used for appointments;
  • appointment-sid - the order key used for appointments;
  • employee-synckey - the secure key used for the ICS syncing of an employee;
  • packorder-sid - the order key used for packages orders;
  • subscr-sid - the order key used for subscriptions orders;
  • synckey - the secure key used for the global ICS syncing;
  • usernote-secret - the secret key used to build private folders;
  • webhook-logkey - the secret key used for log files holding web hooks requests.

The scope will be null only in case a third-party plugin calls the VikAppointments::generateSerialCode($length, $scope, $map) method by omitting the $scope argument.


Example

The following example alters the default generation of a coupon code. Any generated coupon will start with "CPN" prefix and will contain only uppercase letters.

/**
 * This event can be used to change the way the system generates a serial code.
 * It is possible to edit the code or simply to alter the map of allowed tokens.
 * In case the serial code didn't reach the specified length, the remaining
 * characters will be generated according to the default algorhytm.
 *
 * @param  boolean  $status  True on success, false otherwise.
 * @param  string   &$code   The serial code.
 * @param  array    &$map    A lookup of allowed tokens.
 * @param  integer  $length  The length of the serial code.
 * @param  mixed    $scope   The purpose of the code.
 */
add_filter('vikappointments_generate_serial_code', function($status, &$code, &$map, $length, $scope)
{
    if ($scope == 'coupon')
    {
        // always start with "CPN"
        $code = 'CPN';
        // use only letters
        $map = array('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
    }

    return $status;
}, 10, 5);

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2021-07-29
Utile?
This site uses cookies. By continuing to browse you accept their use. Further information