English (United Kingdom)
Knowledge Base  >  Vik Appointments  >  Hooks  >  Payment  >  Fetch Available

apply_filters( 'vikappointments_fetch_available_payment_methods', bool $status, mixed &$query, string $group, array $options )

Fires while loading all the available methods of payment.


Description

Trigger hook to allow the plugins to manipulate the query used to retrieve the available payment gateways.

It is possible to apply further restrictions or to select additional columns from external database tables.


Parameters

$status

(bool)  True on success, false otherwise.

&$query

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

$group

(string)  The group to which the payments belong (appointments, packages or subscriptions).

$options

(array)  An array of options to filter the payments.

  • id_employee - takes only the payments assigned to the specified employee (for appointments group only);
  • strict - validates the publishing options of the payment (by default it relies on the current client section).

Example

The example below excludes the payment with ID 5 for guest users.

/**
 * Trigger event to allow the plugins to manipulate the query used to retrieve
 * the available payment gateways.
 *
 * @param  bool    $status   True on success, false otherwise.
 * @param  mixed   &$query   The query string or a query builder object.
 * @param  string  $group    The group to which the payments belong.
 * @param  array   $options  An array of options to filter the payments.
 */
add_filter('vikappointments_fetch_available_payment_methods', function($status, &$query, $group, $options)
{
    if (VikAppointments::isUserLogged())
    {
        // always exclude the payment method with ID 5 in case of guest user
        $query->where('id <> 5');
    }

    return true;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Last Update: 2021-07-29
Helpful?