Back to Main Site

挂钩:cart.totals

Last updated on Jun 24, 2026 01:54

## 概述

类型: 过滤器 位置: app/Services/Ecommerce/CartService.php

在返回给客户端之前过滤计算出的购物车总计。用于自定义折扣、附加费或费用调整。

## 参数

参数 类型 描述
$totals array 计算总计(小计、税费、运费、总计)
$cart Cart 带有物品的购物车模型

## 返回

必须返回“array”-修改后的总计。

使用示例

Hook::addFilter('cart.totals', function (array $totals, $cart) {
    if ($totals['subtotal'] < 100000) {
        $totals['total'] += 15000; // handling fee for small orders
    }
    return $totals;
});

相关挂钩