woothemes/woocommerce — pull request #4182 by thenbrent (2013-11-22 23:36:04+00:00)
Title: Check products are purchasable when restoring cart

Version of #4082 that is:

* for the master branch (so in different file and using the new `wc_add_notice()` function)
* includes `WC_Cart::get_cart_for_session()` based on @mikejolley's [feedback](https://github.com/woothemes/woocommerce/pull/4082#issuecomment-28489465).

All tested and working.

From #4082:

> Because `WC_Product::is_purchasable()` is only called when adding a product to the cart, it's possible to purchase products that aren't purchasable (but were purchasable when they were first added to the cart).

> This patch checks all of the cart's contents when restoring the cart from the session to make sure that each of them is purchasable. If they're not, it removes them from the cart session, doesn't add them to the cart and display's an error message notifying the customer that the item was removed.

> It's tested & working, but I'm not sure what I've done to remove the item from the cart session is the best approach i.e. [`$woocommerce->session->cart = $this->cart_contents`](https://github.com/thenbrent/woocommerce/commit/1d599b5#diff-6d49d784315a8c9815e4f600dafe95e6L150). If it is and this is merged as is, I'll patch WC 2.1 too.

> Relates to ZD ticket 116028.