Italian (Italy)
Knowledge Base  >  Vik Booking  >  Per Programmatori  >  Check-In e Pre Check-in  >  Pre Check-In (registrazione in front-end)  >  Definire campi personalizzati per la raccolta dei dati prima del check-in
1.6

do_action( 'vikbooking_display_precheckin_pax_fields', array &$precheckin_pax_fields )

Fires before displaying the data collection fields during pre check-in for each guest in the front-end reservation details page.


Description

Plugins can use this filter to manipulate at runtime the fields requested to each guest during pre check-in by adding custom HTML input elements of any type.

Please note this should be used only if the default pre check-in fields do not meet your requirements.


Parameters

&$precheckin_pax_fields

(array)  The two-dimension array containing the default pre check-in fields with their respective keys (names) and attributes (types).

This is how the hook will fire. In order to customize (modify) the information (fields) requested to each guest it is necessary to modify the properties of the array passed by reference.


Same fields for pre-checkin and back-end registration

This hook describes how to define (overwrite) the pre-checkin guest registration fields. The system will load a list of pre-defined fields for the pre-checkin, or the list of pre-defined fields for pre-checkin can be returned by your active guest data collection driver.

If you are developing a custom plugin (driver) for the guest data collection and if you would like to have the same custom fields during the pre-checkin as well as during the back-end guests registration, then you should declare the method listPrecheckinFields as explained in the section Data Collection Driver File.

Use this hook to simply manipulate at runtime the fields for pre-checkin before they are rendered and displayed.


Example

The example below shows how to quickly add some additional fields to the default ones, and those unwanted could be simply unset.

Please notice that this example integrates what's described in the "Main plugin file" section to load a custom driver for the back-end guests registration (Check-in). If you are only interested in overriding the front-end pre check-in fields, then you should focus only on how to define the hook for the event vikbooking_display_precheckin_pax_fields.

<?php
/*
Plugin Name:  VboCustomCheckinDriver
Plugin URI:   https://vikwp.com/plugin/vikbooking
Description:  Custom check-in driver for guests data collection in VikBooking.
Version:      1.0.0
Author:       E4J s.r.l.
Author URI:   https://vikwp.com
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
Text Domain:  vbocustomcheckindriver
*/

// no direct access
defined('ABSPATH') or die('No script kiddies please!');

// register callback for filter "vikbooking_load_paxdatafields_drivers"
add_filter('vikbooking_load_paxdatafields_drivers', function($return)
{
    if (!$return)
    {
        $return = [];
    }

    /**
     * Since multiple plugins could add their own custom drivers, it is
     * necessary to always merge the paths to the driver files of this
     * plugin to any previous widget that may have already been injected.
     * Simply define an array of absolute paths to the PHP files that declare
     * the needed class by VikBooking to load a custom check-in driver.
     * 
     * In this example, we are telling VikBooking to load one custom check-in driver.
     */
    return array_merge($return, [
        // WP_PLUGIN_DIR          = absolute server path to plugin's directory
        // vbocustomcheckindriver = the name of this custom plugin
        // drivers                = a private/internal folder of this custom plugin
        // my_country.php         = the class file that declares the driver
        WP_PLUGIN_DIR . '/vbocustomcheckindriver/drivers/my_country.php',
    ]);
});

// register action to manipulate the pre-checkin pax registration fields
add_action('vikbooking_display_precheckin_pax_fields', function(&$precheckin_pax_fields) {
    if (!is_array($precheckin_pax_fields) || !$precheckin_pax_fields) {
        // some other plugins may have unset the pre-checkin fields array
        return;
    }

    // we append the same type of custom field "myinfo" used for the back-end guests check-in registration

    // append the name of the custom field (key)
    $precheckin_pax_fields[0]['myinfo'] = __('Custom Information', 'vbocustomcheckindriver');

    // append the attribute of the custom field (type)
    $precheckin_pax_fields[1]['myinfo'] = 'mycountry_myinfo';

    // we also append a custom field of type text

    // append the name of the custom field (key)
    $precheckin_pax_fields[0]['food_allergies'] = __('Food allergies?', 'vbocustomcheckindriver');

    // append the attribute of the field (type)
    $precheckin_pax_fields[1]['food_allergies'] = 'text';
}, 10, 3);

// make sure to load (require) the PHP Class of the custom driver "mycountry"
add_action('plugins_loaded', function()
{
    require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'drivers' . DIRECTORY_SEPARATOR . 'my_country.php';
});

If you are willing to copy the whole code snippet above to build your own custom plugin, then you should be aware of the fact that other files will have to be provided, because the above example is an integration of what was described for the back-end check-in data collection during the guests registration.

For more details, please refer to the related sections of this content.

Ultimo aggiornamento: 1 settimana fa
Utile?
63% delle persone lo ha trovato utile.