Search Available
apply_filters( 'vikrestaurants_search_available_payment', bool $accept, object $payment, string $group )
Fires while checking whether a payment gateway can be used or not.
Description
Trigger hook to let external plugins apply additional filters while searching for a compatible payment gateway. The filter applies once for each payment gateway separately.
When this hook is triggered, the system already validated the standard conditions and the payment gateway has been approved for the usage.
In case the payment is discarded, it won't be reported within the selection list of payments.
Parameters
- $accept
-
(bool) Use false to discard the payment gateway.
- $payment
-
(object) An object holding the details of the payment to check.
- $group
-
(string) The section in which the customer is paying ("restaurant" or "takeaway").
Example
The example below automatically turns off a specific payment during Summer.
/**
* Trigger event to let external plugins apply additional filters while
* searching for a compatible payment gateway.
* The hook will be executed only in case all the other filters
* accepted the payment for the usage.
*
* @param bool $accept True to accept the payment, false to discard it.
* @param object $payment The payment database record.
* @param string $group The group to check ("restaurant" or "takeaway").
*/
add_filter('vikrestaurants_search_available_payment', function($accept, $payment, $group) {
if ($payment->id != 5) {
// go ahead
return $accept;
}
// payment found, get current month
$mon = (int) date('n');
// make sure we are not in Summer
if (in_array($mon, [6, 7, 8]) {
// discard payment
$accept = false;
}
return $accept;
}, 10, 3);
Changelog
Version | Description |
---|---|
1.3 | The $group argument has been changed from int to string and the accepted types have been changed accordingly: 1 in "restaurant"; 2 in "takeaway".Removed the $user and $total arguments as they were out of context. |
1.2 | Introduced. |
Ultimo aggiornamento: 2023-12-27
Utile?