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

apply_filters_ref_array( 'vikappointments_manipulate_available_payment_methods', bool $status, array &$payments, string $group, array $options )

Fires before returning the available methods of payment.


Description

Trigger hook to allow the plugins to manipulate the list containing all the payment methods that are going to be displayed.

Here it is possible to discard specific payments or even add new ones at runtime.


Parameters

$status

(bool)  True on success, false otherwise.

&$payments

(array)  An array of available payments (objects).

$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 automatically turns off a specific payment during Summer.

/**
 * Trigger event to allow the plugins to manipulate the list containing
 * all the payment methods that are going to be displayed.
 *
 * @param  boolean  $status     True on success, false otherwise.
 * @param  array    &$payments  An array of available payments.
 * @param  string   $group      The group to which the payments belong.
 * @param  array    $options    An array of options to filter the payments.
 */
add_filter('vikappointments_manipulate_available_payment_methods', function($status, &$payments, $group, $options)
{
    // get current month
    $mon = (int) JHtml::_('date', 'now', 'n');

    // make sure we are not in Summer
    if (!in_array($mon, [6, 7, 8])
    {
        return true;
    }

    // we are in summer, get rid of payment with ID #5
    $payments = array_filter($payments, function($p)
    {
        return $p->id != 5;
    });

    return true;
}, 10, 4);

Changelog

Version Description
1.2 Introduced.
Last Update: 2023-04-05
Helpful?

This website uses cookies

This website uses cookies and similar technologies. Some of these technologies are necessary for the proper functioning of the website (Essential). Other technologies are used to evaluate user behavior (Analysis), to integrate external media or for advertising purposes. If you agree, these technologies are activated. For details, please refer to the privacy policy. From this same page you can also update/revoke your consent. If you do not give your consent, only cookies with essential functions will be activated.

We use technologies from the USA on our website. If you give your consent, you therefore consent at the same time to your data being transferred to the USA. We would like to point out that the USA does not have a level of data protection comparable to that of the EU and that any US company can be obliged by state authorities to hand over your data without you having any effective legal protection against this.