This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
A client wants it so that it's not possible for customers to select product attribute pulldown combinations that refer to either non-existent or out of stock variations (they don't like customers making a selection from four pulldowns only to be told it's invalid). I took a stab at coding a solution that mostly works. https://gist.github.com/rhaglennydd/b7a3ed4102811f613ecb614e3b7082c7
From functions.php
the class SingleProduct
is instantiated and the setup
method is called to kick things off. The JavaScript is in the productVariationFooterScript
method. Every time the user selects an option from an attribute pulldown an AJAX request is made, which is handled by the method ajaxFilterProductAttributeOptions
(it returns valid options for all the other pulldowns, which then get updated by JavaScript). Like I say it mostly works, the attribute pulldown options are filtered properly for the most part, the only hitch I've found is that if the user makes selections from the first three pulldowns sometimes they can hit a combination for which any of the options for the last pulldown results in an out of stock variation. (There are variations like this in the system.) Thus no options are returned for that pulldown via AJAX, so its options are unchanged. I suspect this code needs to be reworked substantially to be more intelligent, maybe involving recursion, but I'm not sure how I would go about it.
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/woocommerce...