Skip Navigation

[Resolved] How to list variable products thanks to a Views

This support ticket is created 3 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Pat 3 years, 2 months ago.

Author
Posts
#2175733

Pat

Hello,

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 :

		<wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]-[wpv-post-field name="views_woo_price"]€"}
		</wpv-loop>

And then, I'm using integrating this Views inside a Cred in order to be able to make a choice in the frontend form:

<div class="form-group">
		<label>Choix de la sortie</label>
		[cred_generic_field type='select' field='wpcf-id-du-produit-achete']
{
"required":0,
"persist":1,
"options":[[wpv-view name="backoffice-select-sortie"]]
}
[/cred_generic_field]
	</div>

Could you explain how I can manage this for variable products?
Regards
Pat

#2176101

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Pat

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.

#2182619

Pat

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