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


PHP WHMCS CartTotalAdjustment用法及代码示例


在计算订单总额时调用,这可用于操纵最终总额。

参数

变量 类型 注意
products array 购物车中产品的索引数组。键包括piddomainbillingcycleconfigoptionscustomfieldsaddonsserverhostname
domains array 购物车中的域注册和转移的索引数组。键包括 typedomainregperiod

响应

返回一个由调整 descriptionamounttaxed 组成的数组(布尔)

示例代码

<?php

add_hook('CartTotalAdjustment', 1, function($vars) {
    $cart_adjustments = array();

    $products = $tlds = [];

    foreach ($vars['products'] as $product) {
        $products[] = $product['pid'];
    }

    foreach ($vars['domains'] as $domain) {
        if ($domain['type'] == 'register') {
            $domainParts = explode('.', $domain['domain'], 2);
            $tlds[] = $domainParts[1];
        }
    }

    if (in_array(1, $products) && in_array('co.uk', $tlds)) {
        $cart_adjustments = [
            "description" => "Custom discount for buying product 1 and a co.uk domain",
            "amount" => "-18.00",
            "taxed" => false,
        ];
    }
    return $cart_adjustments;
});

相关用法


注:本文由纯净天空筛选整理自whmcs.com大神的英文原创作品 CartTotalAdjustment。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。