Italian (Italy)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Campi  >  Before Register

do_action_ref_array( 'vikrestaurants_before_register_custom_fields', array &$rows )

Fires after loading the available custom fields from the database.


Description

Trigger hook to allow external plugins to manipulate the list of available custom fields at runtime.

Here it is possible to detach certain fields, append new fields and rearrange their ordering.

When registering a new custom field, it is possible to specify all the following properties.

name

(string)  The name of the field to store in the database, as short as possible (required).

langname

(string)  The label of the field to display. If not provided, the label will be equals to the name property.

description

(string)  A long description to be displayed inside a tooltip (optional).

type

(string)  The type of the custom field (required). The system supports by default the following types: text, textarea, checkbox, passwordselect, date, number and separator.

choose

(string)  A configuration JSON/string depending on the specified custom field type (optional).

multiple

(bool)  True in case the field supports the selection of multiple values (optional). Available only for select type.

required

(bool)  True in case the field requires a selection (optional).

rule

(string)  An optional rule to dispatch when loading the entered value for this custom field (optional). The system supports by default the following rules: nominative, email, phone, state, city, address, zip, companyvatnum, delivery notes and reservation notes.

poplink

(string)  A URL/query string to reach (optional). Available only for checkbox type.

group

(int)  The group for which the field should be used ("0" for restaurant, "1" for take-away).


Parameters

$rows

(array)  An array containing all the supported custom fields (objects).


Example

The example below explains how to register a new "Privacy Policy" checkbox without having to create it as a custom field.

/**
 * Trigger hook to allow external plugins to manipulate the list of
 * available custom fields through this helper class.
 *
 * @param  object[]  &$rows  An array of custom fields records.
 */
add_action('vikrestaurants_before_register_custom_fields', function(&$rows) {
    // register a new checkbox to collect the privacy policy
    $privacyPolicy = (object) [
        'name'        => 'privacypolicy',
        'langname'    => 'I hereby authorize the use of my personal data',
        'description' => '<p>The description of the field goes here.</p>',
        'type'        => 'checkbox',
        'multiple'    => false,
        'required'    => true,
        'rule'        => '',
        'poplink'     => 'https://domain.com/privacy-policy',
        'group'       => 0, // available for the restaurant group
    ];

    $rows[] = $privacyPolicy;

    // clone the field to support the take-away group too
    $privacyPolicy = clone $privacyPolicy;
    $privacyPolicy->group = 1; // available for the take-away group
    $rows[] = $privacyPolicy;
});

Changelog

Version Description
1.3 Introduced.
Ultimo aggiornamento: 2023-12-28
Utile?
Potrebbe interessarti:
This site uses cookies. By continuing to browse you accept their use. Further information