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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。