woocommerce_add_to_cart хук-событиеWC 1.0

Fires when an item is added to the cart.

This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.


add_action( 'woocommerce_add_to_cart', 'wp_kama_woocommerce_add_to_cart_action', 10, 6 );
function wp_kama_woocommerce_add_to_cart_action( $cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data ){
	// action...
ID of the item in the cart.
ID of the product added to the cart.
Quantity of the item added to the cart.
Variation ID of the product added to the cart.
Array of variation data.
Array of other cart item data.

Где вызывается хук

woocommerce/packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php 147-155
	$this->get_product_id( $product ),
	$this->get_variation_id( $product ),
woocommerce/includes/class-wc-cart.php 1276
do_action( 'woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data );

Где используется хук в WooCommerce

woocommerce/includes/class-wc-cart-session.php 55
add_action( 'woocommerce_add_to_cart', array( $this, 'persistent_cart_update' ) );
woocommerce/includes/class-wc-cart-session.php 61
add_action( 'woocommerce_add_to_cart', array( $this, 'maybe_set_cart_cookies' ) );
woocommerce/includes/class-wc-cart.php 106
add_action( 'woocommerce_add_to_cart', array( $this, 'calculate_totals' ), 20, 0 );
woocommerce/includes/class-wc-form-handler.php 857
remove_action( 'woocommerce_add_to_cart', array( WC()->cart, 'calculate_totals' ), 20, 0 );
woocommerce/includes/class-wc-form-handler.php 864
add_action( 'woocommerce_add_to_cart', array( WC()->cart, 'calculate_totals' ), 20, 0 );