I'm using Toolset + WC and need to list all products based on some parameters. For simple products, this is easy but for variable products, I'm not sure how to proceed.
The aim is to be able to chose a product and its price (one in case of simple product and several based on the number of variations for variable)
Here is for example, what I'm using inside the Views for simple products :
This may be a little tricky given that you are trying to output the View in JSON format so that it can be used to provide values for a form generic select field, and any unexpected whitespace etc. is enough to break this.
First you need to understand how the underlying data is stored.
So, products are posts. Variable products are also stored as posts, but with a post_type of product_variation, where post_parent is set to the master product post.
So you would need nested Views for this.
The main outer View queries products. A nested View queries product_variation posts where post_parent is set by the current iteration of the outer View.
You would output nothing if there was no matching post in this nested View, or—given that most products may well not be variable products—you could insert the nested View with a conditional shortcode that checks the product_type taxonomy of the current product to see if it is variable.
I haven't tried using nested Views to generate JSON options before, and given how demanding it can be regarding formatting I'm not entirely confident it will work, but that is how you would go about it.
Hi Nigel,
Thanks for the direction !
My opinion is that Toolset should evolve to manage entirely WC products, including variable products. For info, I have raised the question some months ago and there is no way to create a variable product in the front end using Forms, which is to me, an issue concerning Toolset Forms.
Regards
Pat