Your cart is empty!
Add Item
apply_filters_ref_array( 'vikappointments_add_package_item_cart', bool $accept, VAPCartPackages $cart, VAPCartPackagesItem &$item, string &$err )
Fires before adding a new item (package) into the cart.
Description
Trigger hook before adding a new package into the shopping cart.
It is possible to use this hook to prevent the customers from adding specific packages into the cart or to manipulate them at runtime.
Parameters
- $accept
-
(bool) True to add the package into the cart, false to discard it.
- $cart
-
(VAPCartPackages) The cart instance.
- &$item
-
(VAPCartPackagesItem) The item that is going to be added into the cart.
- &$err
-
(string) When the item is going to be discarded, it is possible to fill this argument with an error message, which will be prompted to the customer.
$err = 'You are not allowed to purchase this package!'; return false;
Example
/**
* Trigger hook before adding an item into the cart.
*
* @param boolean $accept True to add the item, false otherwise.
* @param mixed $cart The cart instance.
* @param mixed &$item The cart item object.
* @param string &$err String used to raise custom errors.
*/
add_filter('vikappointments_add_package_item_cart', function($accept, $cart, &$item, &$err)
{
/**
* @todo do stuff here
*/
return $accept;
}, 10, 4);
Changelog
Version | Description |
---|---|
1.2 | Introduced. |
Last Update: 2021-10-06
Helpful?