Hook: shipping.calculate_cost
Last updated on May 21, 2026 01:08
Overview
Type: Filter
Location: app/Services/Ecommerce/ShippingCalculator.php
Overrides shipping cost for a specific method. Use for conditional free shipping or zone-based pricing adjustments.
Parameters
| Param | Type | Description |
|---|---|---|
$cost |
float | Calculated shipping cost |
$method |
object | Shipping method |
$cart |
Cart | Cart instance |
Return
Must return float.
Usage Example
Hook::addFilter('shipping.calculate_cost', function ($cost, $method, $cart) {
$subtotal = collect($cart->items)->sum(fn($i) => $i->price * $i->quantity);
return ($subtotal >= 500000) ? 0 : $cost;
});