WordPress filter hook

woocommerce_add_cart_item

Defined by WooCommerce and fired by 13 plugins in total, running on 7M+ sites between them.

“Filters the item being added to the cart.”

How to use woocommerce_add_cart_item

It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'woocommerce_add_cart_item', function( $merge, $cart_id ) {
	// Change $merge here.
	return $merge;
}, 10, 2 );

Argument names come from WooCommerce's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

13 plugins that fire woocommerce_add_cart_item

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. WooCommerce icon WooCommerce7+ million installs apply_filters( 'woocommerce_add_cart_item', array_merge( $request['cart_item_data'], array( 'key' => $cart_id, 'product_id' => $this->get_product_id( $product ), 'variation_id' => $this->get_variation_id( $product ), 'variation' => $request['variation'], 'quantity' => $request_quantity, 'data' => $product, 'data_hash' => wc_get_cart_item_data_hash( $product ), ) ), $cart_id ) src/StoreApi/Utilities/CartController.php:171
  2. MoreConvert Wishlist for WooCommerce icon MoreConvert Wishlist for WooCommerce8,000+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $meta, array( 'key' => '', 'product_id' => $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id(), 'variation_id' => $product->is_type( 'variation' ) ? $product->get_id() : 0, 'variation' => $meta['attributes'] ?? array(), 'quantity' => $this->get_quantity(), 'data' => $this->get_product(), 'data_hash' => '', ) ), '' ) includes/class-wlfmc-wishlist-item.php:249
  3. YITH WooCommerce Product Bundles icon YITH WooCommerce Product Bundles3,000+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'key' => $cart_item_key, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data, ) ), $cart_item_key ) includes/class.yith-wcpb-frontend.php:201
  4. MStore API icon MStore API2,000+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'key' => $cart_item_key, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data, 'data_hash' => wc_get_cart_item_data_hash($product_data), ) ), $cart_item_key ) controllers/flutter-woo.php:668
  5. Salevo Boost Sales for WooCommerce icon Salevo Boost Sales for WooCommerce200+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data ) ), $cart_item_key ) frontend/bundles.php:430
  6. One Click Order icon One Click Order10+ installs apply_filters( 'woocommerce_add_cart_item', array( 'key' => $key, 'product_id' => $line['product_id'], 'variation_id' => $line['variation_id'], 'variation' => $line['variation'], 'quantity' => $line['quantity'], 'data' => $line['product'], 'data_hash' => wc_get_cart_item_data_hash( $line['product'] ), ), $key ) includes/class-order-builder.php:185
  7. Discountify icon Discountify10+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'key' => $free_cart_key, 'product_id' => $data['product_id'], 'variation_id' => $data['variation_id'], 'variation' => $data['variation'], 'quantity' => $data['free_qty'], 'data' => $free_product, 'data_hash' => wc_get_cart_item_data_hash( $free_product ), ) ), $free_cart_key ) core/frontend/frontend.php:886
  8. QODE Product Bundles for WooCommerce icon QODE Product Bundles for WooCommerce10+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'key' => $cart_item_key, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $bundle_product, ) ), $cart_item_key ) inc/bundle-product/class-qode-product-bundles-for-woocommerce-bundle-product.php:266
  9. Products Wizard Lite for WooCommerce icon Products Wizard Lite for WooCommerce10+ installs apply_filters( 'woocommerce_add_cart_item', $cartItem, $cartItemKey ) includes/classes/Cart.php:613
  10. Norsani API icon Norsani API10+ installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'key' => $cart_item_key, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variations, 'quantity' => $quantity, 'data' => $product_data, 'data_hash' => wc_get_cart_item_data_hash( $product_data ), ) ), $cart_item_key ) includes/api-functions.php:166
  11. QuoteLane icon QuoteLaneFewer than 10 installs apply_filters( 'woocommerce_add_cart_item', $line, 'qlane' ) includes/class-line-options.php:39
  12. MikhailKyrychenko Offer Builder for WooCommerce icon MikhailKyrychenko Offer Builder for WooCommerceFewer than 10 installs apply_filters( 'woocommerce_add_cart_item', $cart_item, $key ) includes/class-hlpb-cart-section.php:1692
  13. Kit Product For Woocommerce icon Kit Product For WoocommerceFewer than 10 installs apply_filters( 'woocommerce_add_cart_item', array_merge( $cart_item_data, array( 'kit_id' => $kit_parent_id, 'product_id' => $product_id, 'variation_id' => $variation_id, 'variation' => $variation, 'quantity' => $quantity, 'data' => $product_data, ) ), $cart_item_key ) inc/class-cart-work.php:206

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.