當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP WHMCS NotificationPreSend用法及代碼示例

在發送通知之前執行以允許應用附加條件標準和處理通知消息。

參數

變量 類型 注意
eventType string 事件類型例如:票證、發票、訂單、服務或域
eventName string 事件名稱。
rule \WHMCS\Notification\Rule 已匹配的通知規則模型。
hookParameters array 鉤子參數數組。會因觸發器而異。
notification \WHMCS\Notification\Notification 通知對象。請參閱https://docs.whmcs.com/classes 的課程文檔

響應

不支持響應

示例代碼

<?php

add_hook('NotificationPreSend', 1, function($vars) {

    $eventType = $vars['eventType'];
    $eventName = $vars['eventName'];
    $rule = $vars['rule'];
    $hookParameters = $vars['hookParameters'];
    $notification = $vars['notification'];

    // Perform additional conditional logic and throw the AbortNotification
    // exception to prevent the notification from sending.
    if ($eventType == 'Invoice'
        && $eventName == 'created'
        && (isset($hookParameters['invoiceid'])
            && $hookParameters['invoiceid'] > 1000)
    ) {
        throw new \WHMCS\Notification\Exception\AbortNotification();
    }

    // If allowing the notification to continue, you can manipulate the
    // notification using the \WHMCS\Notification\Notification object.
    $notification->setTitle('Override notification title');
    $notification->setMessage('Override notification message body');

});

相關用法


注:本文由純淨天空篩選整理自whmcs.com大神的英文原創作品 NotificationPreSend。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。