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


PHP WHMCS OrderProductPricingOverride用法及代碼示例

在購物車中計算產品價格時執行。

參數

變量 類型 注意
key int 購物車會話中產品的 key
pid int 產品編號
proddata array 產品資料

響應

產品定價可以被覆蓋——不包括可配置的選項成本。接受 key ‘setup’ and ‘recurring’ 的返回。例如:返回數組(‘setup’ => 1.00,‘recurring’ => 12.00);

示例代碼

<?php

use WHMCS\Authentication\CurrentUser;

add_hook('OrderProductPricingOverride', 1, function($vars) {
    $return = [];

    /**
     * Get the logged in client. Returns null if no client logged in.
     *
     * @see https://developers.whmcs.com/advanced/authentication/
     */
    $client = CurrentUser::client();

    /**
     * Run the following rules if a Client is logged in.
     */
    if ($client) {
        /**
         * Override the product price when ordering product 1 and the user has the ID 10.
         */
        if ($vars['pid'] == 1 && $client->id == 10) {
            $return = ['setup' => '0.00', 'recurring' => '0.00',];
        }

        /**
         * Override the product price when user has the ID 72.
         */
        if ($client->id == 72) {
            $return = ['setup' => '0.00', 'recurring' => '0.00',];
        }
    }
    return $return;
});

相關用法


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