woocommerce_add_cart_item_data
Filter cart item data for add to cart requests.
Usage
add_filter( 'woocommerce_add_cart_item_data', 'wp_kama_woocommerce_add_cart_item_data_filter', 10, 4 ); /** * Function for `woocommerce_add_cart_item_data` filter-hook. * * @param array $cart_item_data Array of other cart item data. * @param integer $product_id ID of the product added to the cart. * @param integer $variation_id Variation ID of the product added to the cart. * @param integer $quantity Quantity of the item added to the cart. * * @return array */ function wp_kama_woocommerce_add_cart_item_data_filter( $cart_item_data, $product_id, $variation_id, $quantity ){ // filter... return $cart_item_data; }
- $cart_item_data(array)
- Array of other cart item data.
- $product_id(int)
- ID of the product added to the cart.
- $variation_id(int)
- Variation ID of the product added to the cart.
- $quantity(int)
- Quantity of the item added to the cart.
Changelog
Since 2.5.0 | Introduced. |
Where the hook is called
woocommerce_add_cart_item_data
woocommerce_add_cart_item_data
woocommerce/src/StoreApi/Utilities/CartController.php 1155-1161
$request['cart_item_data'] = (array) apply_filters( 'woocommerce_add_cart_item_data', $request['cart_item_data'], $product_id, $variation_id, $request['quantity'] );
woocommerce/includes/class-wc-cart.php 1145
$cart_item_data = (array) apply_filters( 'woocommerce_add_cart_item_data', $cart_item_data, $product_id, $variation_id, $quantity );