woocommerce_add_cart_item_data filter-hookWC 2.5.0

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

CartController::filter_request_data()
woocommerce_add_cart_item_data
WC_Cart::add_to_cart()
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 );

Where the hook is used in WooCommerce

Usage not found.