woocommerce_store_api_validate_add_to_cart
Fires during validation when adding an item to the cart via the Store API.
Fire action to validate add to cart. Functions hooking into this should throw an \Exception to prevent add to cart from happening.
Usage
add_action( 'woocommerce_store_api_validate_add_to_cart', 'wp_kama_woocommerce_store_api_validate_add_to_cart_action', 10, 2 ); /** * Function for `woocommerce_store_api_validate_add_to_cart` action-hook. * * @param \WC_Product $product Product object being added to the cart. * @param array $request Add to cart request params including id, quantity, and variation attributes. * * @return void */ function wp_kama_woocommerce_store_api_validate_add_to_cart_action( $product, $request ){ // action... }
- $product(\WC_Product)
- Product object being added to the cart.
- $request(array)
- Add to cart request params including id, quantity, and variation attributes.
Changelog
Since 7.1.0 | Introduced. |
Where the hook is called
woocommerce_store_api_validate_add_to_cart
woocommerce/src/StoreApi/Utilities/CartController.php 335
do_action( 'woocommerce_store_api_validate_add_to_cart', $product, $request );