This is a rough proposal - basically food for thought. The supplied
code has NOT been tested.
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' to work, but it's
always a good idea to make the core code a bit more flexible.
Function currently only echos. Commit enables function to return product
image. WCP+A replaces the product thumbnail with photo preview
thumbnail. Original function showed two thumbnails directly next to each
other.
Useful for hiding dummy cart items.
"Product Bundles" uses this to only show bundled products when pricing
is per-item (emphasis on contents), or to hide them when pricing is
fixed for the whole bundle (emphasis on bundle).