WordPress action hook

woocommerce_add_to_cart

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

“Fires when an item is added to the cart.”

How to use woocommerce_add_to_cart

It's an action: your callback runs at that point and receives 6 arguments. Nothing needs to be returned. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_action( 'woocommerce_add_to_cart', function( $cart_id, $arg2, $request_quantity, $arg4, $request, $request2 ) {
	// Your code runs here.
}, 10, 6 );

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

3 plugins that fire woocommerce_add_to_cart

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

  1. WooCommerce icon WooCommerce7+ million installs do_action( 'woocommerce_add_to_cart', $cart_id, $this->get_product_id( $product ), $request_quantity, $this->get_variation_id( $product ), $request['variation'], $request['cart_item_data'] ) src/StoreApi/Utilities/CartController.php:217
  2. MStore API icon MStore API2,000+ installs do_action( 'woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) controllers/flutter-woo.php:688
  3. Formdev icon Formdev10+ installs do_action( 'woocommerce_add_to_cart', $cart_item_key, $wp_product_id, 1, 0, array(), array() ) formdev.php:346

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.