当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。