English (United Kingdom)

apply_filters_ref_array( 'vikappointments_build_service_search_query', bool $status, mixed &$queryarray &$options )

Fires while loading the service to display.


Description

Trigger hook to manipulate at runtime the query used to load the service to display under the Service Details page in the front-end.

Third party plugins can extend the query by applying further conditions or selecting additional data.


Parameters

$status

(bool)  True on success, false otherwise.

&$query

(mixed)  Either a query builder object or a plain string.

&$options

(array)  An array of options.

  • id_service - the ID of the service to load;
  • id_employee - the ID of the employee assigned to the specified service.

Example

The example below auto-unpublishes the service with ID #5 when we currently are in Summer.

/**
 * Trigger hook to manipulate the query at runtime. Third party plugins
 * can extend the query by applying further conditions or selecting
 * additional data.
 *
 * @param  boolean  $status    True on success, false otherwise.
 * @param  mixed    &$query    Either a query builder or a query string.
 * @param  array    &$options  An array of options.
 */
add_filter('vikappointments_build_service_search_query', function($status, &$query, &$options)
{
    // check if we are trying to fetch a specific service
    if ($options['id_service'] != 5)
    {
        return true;
    }

    // get current month
    $mon = (int) JHtml::_('date', 'now', 'n');

    // check if we are in Summer
    if (in_array($mon, [6, 7, 8]))
    {
        // quick statement to always return no rows
        $query->where(0);
    }

    return true;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Last Update: 2022-01-28
Helpful?
See Also:
This site uses cookies. By continuing to browse you accept their use. Further information