Skip Navigation

[Resolved] Display Product Variations as Separate Products in Loop

This support ticket is created 6 years, 6 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 1 reply, has 2 voices.

Last updated by Beda 6 years, 6 months ago.

Author
Posts
#924807
Screen Shot 2018-07-13 at 11.07.39 AM.png

Currently, I am trying to setup a view that would display all of my products, but I am wanting the loop to see product variations as separate products. I would like the loop to be able to see that I have 3 different sizes for one product, but show each size as its own.

An example would be something like this below. Here is a product, but it has 2 different sizes. Under my wooproducts I would have just 1 product, but with a variation of 2 sizes. The view should display this 1 product 2 times with the variation variables, such as different product images.

#925002

Much easier than to deal with how WooCommerce stores those variations would be to setup a Relationship or even just Repeatable Post Field Group with Toolset and store that information there, so it would be easy to display.

WooCommerce stores Product Variations in a specific way.
If I recall it right, in the posts table the Post Type "product" represents the WooCommerce "Products".
Each variation, is again a Post on it's own, which is represented in the database with Post Type "product_variation".
This is then in turn using the native WordPress Page hierarchy mechanism (you can also add that to Post Types, even in Toolset) "post_parent", to determine the ID of the Product it's belonging to.

Seen from that point it's not much more than displaying the Parent Pages or Child Pages with native WordPress Hierarchy in Toolset Views.

This is theory, gathered as I type and from memory.

Let's try this.

1. Install WooCommerce and Create a variable product with at least 2 variations
2. Install Toolset Views and create a new View in "Full custom display mode", which... and here you will see the

WooCommerce does not store the Variations as a public Post Type.

See the code that registers that post type of WooCommerce:

register_post_type(
			'product_variation',
			apply_filters(
				'woocommerce_register_post_type_product_variation',
				array(
					'label'           => __( 'Variations', 'woocommerce' ),
					'public'          => false,
					'hierarchical'    => false,
					'supports'        => false,
					'capability_type' => 'product',
					'rewrite'         => false,
				)
			)
		);

As soon "'public' => false," is set to "'public' => true," you will be able to query that post type in Views, and set a query filter.
But, the post type as well does not declare hierarchy so - even if it stores the post_parent value, you cannot filter the View properly

It is not intended to work like this by WooCommerce itself.

What you can do, is display the variations as WooCommerce intends it, or, use the Many To Many relation on a Custom Post Type to achieve the same.