Your cart is empty!
Calculate Item Total
do_action_ref_array( 'vikrestaurants_calculate_item_total', float &$total, Item $item )
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.
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.
*/
add_action('vikrestaurants_calculate_item_total', function(&$total, $item) {
// check if we have a user not logged-in
if (wp_get_current_user()->exists() == false) {
// increase item price
$total++;
}
}, 10, 2);
Changelog
Version | Description |
---|---|
1.3 | The hook has been changed from a filter into an action as the plugin didn't need a return value anymore. |
1.1 | Introduced. |
Last Update: 2024-01-04
Helpful?
100% of people found this helpful.