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 for `woocommerce_add_to_cart` action-hook.
 * 
 * @param string  $cart_id          ID of the item in the cart.
 * @param integer $product_id       ID of the product added to the cart.
 * @param integer $request_quantity Quantity of the item added to the cart.
 * @param integer $variation_id     Variation ID of the product added to the cart.
 * @param array   $variation        Array of variation data.
 * @param array   $cart_item_data   Array of other cart item data.
 *
 * @return void
 */
function wp_kama_woocommerce_add_to_cart_action( $cart_id, $product_id, $request_quantity, $variation_id, $variation, $cart_item_data ){

	// action...
}
$cart_id(строка)
ID of the item in the cart.
$product_id(int)
ID of the product added to the cart.
$request_quantity(int)
Quantity of the item added to the cart.
$variation_id(int)
Variation ID of the product added to the cart.
$variation(массив)
Array of variation data.
$cart_item_data(массив)
Array of other cart item data.

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

CartController::add_to_cart()
woocommerce_add_to_cart
WC_Cart::add_to_cart()
woocommerce_add_to_cart
woocommerce/packages/woocommerce-blocks/src/StoreApi/Utilities/CartController.php 159-167
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']
);
woocommerce/includes/class-wc-cart.php 1279
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 68
add_action( 'woocommerce_add_to_cart', array( $this, 'persistent_cart_update' ) );
woocommerce/includes/class-wc-cart-session.php 74
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 );