nexcess/limit-orders

Should we let WooCommerce empty the cart once limits are reached?

Opened this issue · 0 comments

WordPress.org user intriguemediaweb raised an interesting question yesterday: how does a shop owner keep WooCommerce from emptying customer carts once the order threshold has been met?

Digging in, WooCommerce runs WC_Cart_Session::get_cart_from_session() on the "wp_loaded" hook, where it loads up the current cart and filters out anything that is no longer available for purchase.

Meanwhile, Limit Orders uses add_filter('woocommerce_is_purchasable', '__return_false'); as one of the components of OrderLimiter::limit_ordering(), as it prevents WooCommerce from showing the "Add to Cart" button.

The side-effect here is that once the threshold has been hit, the limit_ordering() callback goes into effect, which in-turn causes get_cart_from_session() to remove the now "unpurchasable" items.

I've come up with a filter-based work-around to help in the short term, but it's worth considering if there's a better filter we can use to disable the "Add to Cart" buttons without clearing the carts. Perhaps the answer is to not remove the buttons at all, letting users populate carts but not check out?