woothemes/woocommerce — pull request #1206 by franticpsyx (2012-07-01 15:38:13+00:00)
Title: WC_Cart: Uncouple add_to_cart checks from add_to_cart function

This is a rough proposal. Treat this as food for thought only. The supplied code has NOT been tested and may include very nasty bugs.

In some cases, we may need to do the checking part on multiple products before giving permission to actually add them all to the cart. The reason is that if any product check fails (e.g., out of stock), then no product should be added to the cart and a product-specific error message should be returned, like so: "Product X: The product is out of stock", instead of a vague "The product is out of stock". This is esp useful for Product Bundles, which at the moment handles this by reusing parts of existing code.

Things would be more elegant if an add_to_cart_check function existed. I am not sure if the add_to_cart_check call should exist within add_to_cart, or if there should be 2 separate calls, one for add_to_cart_check and one for add_to_cart, throughout the core codebase.

The supplied woocommerce_add_to_cart_error_message filters would be useful for manipulating the messages to include product-specific info.

Finally, the woocommerce_add_to_cart_…_halt filters would be useful in cases where these checks should not return false. I can image some cases, esp related to bundling.

Note - This is NOT required for 'Product Bundles', but it's always a good idea to make the core code a bit more flexible.