在为购物车和结帐计算税金时调用,这可用于操纵应用于购物车总数或相关结帐付款意图的税率。
参数
变量 | 类型 | 注意 |
---|---|---|
clientData | array | null |
cartData | \ItemInterface[] | 购物车中保存的所有数据的数组。 |
响应
返回操作的ItemInterface 项的数组。税收将从原始项目的增量计算。
示例代码
<?php
use WHMCS\View\Formatter\Price;
add_hook('CartItemsTax', '1', function ($vars) {
$cartItems = $vars['cartData'];
$client = $vars['clientData'];
// Calculate your tax rate to apply
$taxRate = 1.5; // 50%
/** @var \WHMCS\Cart\Item\ItemInterface $item */
foreach ($cartItems as $item) {
if (!$item->isTaxed()) {
continue;
}
/** @var Price $amountToday */
$amountToday = $item->getAmount();
// Set the price due today for the item
$item->setAmount(new Price(
($amountToday->toNumeric() * $taxRate),
$amountToday->getCurrency()
));
if ($item->isRecurring()) {
/** @var Price $recurringAmount */
$recurringAmount = $item->getRecurringAmount();
// Set the recurring price of the item
$item->setRecurringAmount(
new Price(
($recurringAmount->toNumeric() * $taxRate),
$recurringAmount->getCurrency()
)
);
}
}
return [
'cartData' => $cartItems
];
});
相关用法
- PHP WHMCS CartTotalAdjustment用法及代码示例
- PHP WHMCS CartSubdomainValidation用法及代码示例
- PHP CachingIterator __construct()用法及代码示例
- PHP CachingIterator getCache()用法及代码示例
- PHP CachingIterator current()用法及代码示例
- PHP WHMCS CalcAffiliateCommission用法及代码示例
- PHP CachingIterator key()用法及代码示例
- PHP CachingIterator setFlags()用法及代码示例
- PHP WHMCS CapturePayment用法及代码示例
- PHP CachingIterator next()用法及代码示例
- PHP CachingIterator rewind()用法及代码示例
- PHP WHMCS CancellationRequest用法及代码示例
- PHP CachingIterator getFlags()用法及代码示例
- PHP CachingIterator getInnerIterator()用法及代码示例
- PHP WHMCS CancelOrder用法及代码示例
- PHP WHMCS CancelAndRefundOrder用法及代码示例
- PHP WHMCS ClientAreaPageDownloads用法及代码示例
- PHP WHMCS ClientAreaHeaderOutput用法及代码示例
- PHP WHMCS CreateProject用法及代码示例
- PHP WHMCS ClientAreaPageSupportTickets用法及代码示例
- PHP WHMCS ClientAreaPageDomainDNSManagement用法及代码示例
- PHP WHMCS ClientAreaPageAffiliates用法及代码示例
- PHP WHMCS ClientAreaPageViewInvoice用法及代码示例
- PHP WHMCS ClientAreaPageProductsServices用法及代码示例
- PHP WHMCS CustomFieldSave用法及代码示例
注:本文由纯净天空筛选整理自whmcs.com大神的英文原创作品 CartItemsTax。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。