Skip Navigation

[Resuelto] Displaying WC Products which belong to Relationship based on CPT

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

Problem:

We want to pull a list of product IDs which have a Design associated to the Creator you are viewing.

Solution:

It needs a nested view, for example:

https://toolset.com/forums/topic/displaying-wc-products-which-belong-to-relationship-based-on-cpt/#post-1743891

Relevant Documentation:

This support ticket is created hace 4 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por bastienB hace 4 años, 2 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#1743389

Tell us what you are trying to do? Display a list of WooCommerce Products that belong to a Creator (CPT)

Is there any documentation that you are following? Reading this thread here: https://toolset.com/forums/topic/still-confused-about-intermediary-post-for-post-to-post-relationship/

Is there a similar example that we can see? Probably, can't think of any right now.

What is the link to your site? enlace oculto

---

Hey guys,

The purpose is to create a View that returns a list of WC Product IDs we can use in the standard WC shortcode like [products ids="12345,12346,12347"].

-We have the "Creators" CPT which is used for our members profile.
-We have the "Designs" CPT which is used to contain the data required to make a certain custom product.
-We have a one-to-many relationship from Creators => Designs (one Creator may have many Designs)
-We have a one-to-many relationship from Designs => Products (one Design may be used to make many Products)

Now we want to pull a list of product IDs which have a Design associated to the Creator you are viewing.

Link to a Creator profile: enlace oculto

Reading the thread I linked above, it looks like it may be best to use a Taxonomy to link Products to Creators but I don't think Toolset support linking CPTs as custom taxonomies.

Would you please point me in the right direction for setting up this view?

Another approach I was thinking about is to add a WooCommerce attribute "Creator", but this will create an actual attribute-archive for "Creator". We don't want to use a WooCommerce Archive here, so I would need to override this archive with the CPT "Creator" because I want website.com/creator/john-doe to link to the custom profiles.

This would let me use the WooCommerce shortcode [products attribute="creator" terms="john-doe"], where john-doe would be the Creator CPT slug. In terms of query, this is probably more optimized. I would have to make sure that for every new Creator (CPT), I add a corresponding WooCommerce term for the attribute "Creator".

Do you think this is a better approach? Would I be able to replace the WC attribute-archive with our custom CPT?

Thanks a lot!

---

Last thing... How can we add a multiple-value custom field to the CPT edit screen?

Because "Designs" can have color variations we would like to be able to add variations to it. This variation would simply contain a string of text, something like:
-Design ABC
--Colorway #1 => E1:Red;E2:Blue;E3:Black
--Colorway #2 => E1:Green;E2:Yellow;E3:Black
...

My approach is to create a custom field "Colorway(s)" for "Designs" which is a Single Line and I have enabled "Allow multiple instances of this field".

However it looks like I can't display this field on the edit screen. How would I add data to this custom field? Is my approach wrong?

Thank you again!

#1743891

Hello,

Q1) Now we want to pull a list of product IDs which have a Design associated to the Creator you are viewing.

It needs a nested view, for example:
In a single "Creator" post, you can display below nested view:
1) Parent post view:
- Query "Designs" posts
- Filter by post type relationship between "Creator" and "Designs"
- In view's loop, display below child post view

2) Child post view:
- Query "Products" posts
- Filter by post type relationship between "Designs" and "Products"
- Display "Products" post information

Q2) How can we add a multiple-value custom field to the CPT edit screen?
However it looks like I can't display this field on the edit screen. How would I add data to this custom field?
You can follow our document to setup and display the multiple-value custom field:
https://toolset.com/?page_id=10014?page_id=10014
Repeating Fields

#1744849

Hey Luo,

Thanks for the explaination, managed to make this work!

Last question, how would I add a conditional in the Creator profile template so that when the views returns no result, I don't output the WooCommerce shortcode but display a message instead?

Here's the bit that displays the WC shortcode:

                            <div class="e22694-20 x-tabs-panel creations-wrapper" role="tabpanel" aria-labelledby="tab-22694-20" aria-hidden="true" data-x-toggleable="tab-item-22694-20" id="panel-22694-20">
                                <h6 style="text-align: center;">[wpv-post-title] Creations</h6>
                                <div class="x-tabs-content">
                              		[products ids="[wpv-view name='creator-designs']" limit="16" columns="4" orderby="date" order="DESC" paginate="true"]
                                </div>
                            </div>

Maybe it's better if I put the WC shortcode directly in the parent view "creator-designs", but I'm not sure I can split the shortcode like that...

	[wpv-items-found]
	<!-- wpv-loop-start -->
		[products ids="
			<wpv-loop>
				[wpv-item index=other]
					[wpv-view name="creator-products-ids"],
				[wpv-item index=last]
					[wpv-view name="creator-products-ids"]
			</wpv-loop>
		" limit="16" columns="4" orderby="date" order="DESC" paginate="true"]
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]This creator has not published any products yet![/wpml-string]</strong>
	[/wpv-no-items-found]

Thank you!

#1745103

In your case, there isn't such feature, you might consider custom codes, for example, add a custom shortcode, get the view's shortcode [wpv-view name='creator-designs'] results, remove all empty lines and blank spaces, then use it in wpv-conditional shortcode as "if" conditional.

More help:
https://developer.wordpress.org/reference/functions/add_shortcode/
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

#1745887

My issue is resolved now. Thank you!