Your cart is empty!
Calculate Item Total
public function onCalculateItemTotal( float &$total, Item $item ) : void
Fires while calculating the total amount of a take-away item.
Description
Plugins attached to this hook can change the calculated total at runtime. The total cost is meant to be before taxes.
NOTE: calling $item->getTotalCost()
in this hook will result in recursion.
Parameters
- &$total
-
(float) The default total amount. Since this argument is passed by reference, it is possible to manipulate it.
- $item
-
(Item) The object holding the details of the item. This class is part of the
E4J\VikRestaurants\TakeAway\Cart
namespace.
Return Value
None.
Example
The example below always increases by 1 the cost of the items for guest users.
/**
* Plugins attached to this hook can change the calculated total at runtime.
*
* Note. Calling $item->getTotalCost() in this hook will result in recursion.
*
* @param float &$total The calculated total cost.
* @param Item $item The item instance.
*
* @return void
*/
public function onCalculateItemTotal(&$total, $item)
{
// check if we have a user not logged-in
if (JFactory::getUser()->guest) {
// increase item price
$total++;
}
}
Changelog
Version | Description |
---|---|
1.8.2 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?