Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  Pagamento  >  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.
Ultimo aggiornamento: 2023-04-05
Utile?
Potrebbe interessarti: