Skip Navigation

[Resuelto] Create a view for Woocommerce Linked Products field.

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to create a View of linked products to display on the single product template.

Solution: There's no built-in way to do this because of how WooCommerce stores linked products in a serialized data structure. A custom code solution is required.

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 4 respuestas, has 2 mensajes.

Last updated by larryB-3 hace 1 año, 9 meses.

Assigned support staff: Christian Cox.

Autor
Mensajes
#1582497
Screen Shot 2020-04-11 at 2.31.44 PM.jpg

I've entered a few products into the WooCommerce Linked Products field for Upsells. I would now like to create a view to display these linked products on my product page.

#1583387

Hi, WooCommerce stores this information in a serialized array and unfortunately Views is not designed to be able to loop over this kind of information directly. We do provide a shortcode that can be used to display upsell products on the single Product template using a standard WooCommerce format - wpv-woo-show-upsell-items. Unfortunately it is not customizable as a View. Documentation for this shortcode:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-334617

Another User shared a custom code solution that creates a shortcode you can use to generate a list of upsell product IDs. If you can produce a list of upsell product IDs with a custom shortcode, I can show you how to use that shortcode in a View to generate a View of upsell products filtered by product ID using a shortcode attribute. However, since it is custom code I can't debug problems with it. Here is the ticket with more information about this custom code:
https://toolset.com/forums/topic/upsell-and-cross-sell-filter/

If you're able to use this custom code to produce a list of upsell product IDs, I can show you how to use that with a Post IDs Query Filter in a View of Products. Let me know how you would like to proceed.

#1583401

Ok, maybe this can be done another way. Ultimately, I'm trying to create a many to many relationship between items in the same post type (products), is this possible? Create a field, a tag or category that is populated by the list of posts (products) that I can select from to make connections? Then I could create a view of those relationships for a single product?

#1584149

Unfortunately Types Post Relationships and Post Reference fields can only be established between items in different post types. It's a limitation of the currently implemented Post Relationships feature. To relate items from the same post type, a taxonomy or a custom field is required. The main difference between those two options is that taxonomies get automatically created archives, but custom field values do not. I find taxonomies to be easier to manage in wp-admin and Forms, because they implement an autosuggest field so you can begin typing and choose the term easily from a list of suggestions. Custom fields do not implement this type of field, so it makes management more difficult.
Whether you choose to use a custom taxonomy or a custom field, you can then create a View filtered by that criteria and place it on the single Product template to display a list of similar products.

#1584335

My issue is resolved now. Thank you!