Skip Navigation

[Resuelto] Create custom page for WC Products Collection

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Etiquetado: 

Este tema contiene 5 respuestas, tiene 2 mensajes.

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

Asistido por: Nigel.

Autor
Mensajes
#1745985

Tell us what you are trying to do? We have a CPT "Creators" that contains certain members profile. These Creators can publish custom products they make. We want to allow them to order their creations into Collections.

Is there any documentation that you are following? No.

Is there a similar example that we can see? Not really.

What is the link to your site? enlace oculto

---

Hello guys,

Looking for some hints to steer us in the right direction to achieve what we want.

The goal is to display a page that shows a list of Collections, which is a group of WooCommerce Products that our Creators (CPT) can organize their Creations into.

Currently, "Collections" is a WooCommerce attribute as this is used in the product additional information displayed on the single-product page. It can also be used to filter products lists.

Assuming we want to display a custom template for the Collection page instead of the WooCommerce Attribute template, do we necessarily have to link products to "Collections" twice?

What I mean is that if we want to display a custom template, then I think we'll have to create a new CPT "Collection". Then we will create a relationship one-to-many from "Creators" to "Collections" and many-to-many from "Collections" to "Products".

Then when we configure the product, we will have to add the Collection as a WooCommerce attribute **AND** we have to add the relationship from the product to the Collection CPT.

Is this the right approach? Ultimately this will be automated via code but I just want to make sure it's the right approach and I'm not doing things in double.

The reason why we added Collection as a WooCommerce Attribute is that it can be easily used to filter products in listings and is automatically displayed in the product additional information. However, we want to limit the number of "Collections" a "Creator" can make based on his membership level and we want to customize the template that displays the "Collection" (like maybe let the Creator choose a custom banner). For this, the creation of a CPT made sense.

Let me know if I didn't explain clearly enough or if my explanation is confusing and I'll try to rephrase.

Waiting for your feedback.

Thank you!

#1748613

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi there

This sounds like you may be making it more complicated than necessary, but I may be overlooking something.

If you are already using WC Attributes for your Collections, then if you go to Dashboard > Products > Attributes then you can specify that the attribute should have an archive (screenshot, from my test site which has the imported same WC data with Color and Size attributes).

You can then go to Toolset > WordPress Archives and design a custom archive using Toolset (screenshot) for the attribute in question.

In my example I can then visit site.com/color/blue/ to see the product posts with the blue attribute.

Is that not the kind of thing you are aiming for?

#1758425

Hey Nigel,

Thanks for the reply. Let me give you some context.

The WC archive for attributes is limited. For WC categories at least we have a native option to provide a custom image/banner that we can use in our theme. With attributes, there's no such option.

In terms of permission, WC attributes are not designed to be tied to a user. If we want our Creators to create Collections but limit the number of Collections they can create based on their membership level, there will be some extra work to extend WC attributes.

Creators profile are configured in a CPT. Users that register as a Creator are also assigned a special role "nh-creator".

My approach is to add Collections as a CPT. Then we can count easily the number of "Collection" a "Creator" has published. They can also edit some data like the banner image or description, only for the Collections that belong to each Creator.

Now if we want visitors to be able to filter Products by Collection in products listings, the Collection should also be added as a WC Attribute Term. That's where I get a bit tangled and I want to make sure I'm doing things in the most optimal way possible.

The goal is to have...
- A product attribute where terms are added by Creators (CPT + WP Role). Creators may only edit/delete their own terms*

and...
- Products that Creators can group into a Collection (CPT), only if the Product/Collection belongs to the Creator
- Collections (CPT) that can be published by Creators and displayed on their profile (may be limited based on membership level)
- Collection (CPT) template would replace the WooCommerce product attribute archive and display extra metadata like banner, description, creator logo...

*: Because product attribute permissions can't easily be managed at the user-level, it may be easier to handle limitations via a CPT and sync the CPT with WooCommerce when it's saved/updated. So our custom code would count the number of "Collections" (CPT) published by a "Creator" and if this number is equal to the maximum allowed, it won't let the "Creator" publish a new "Collection". If the new collection can be published, our code would use the "Collection" slug and add it as a new term in the "Collection" product attribute. This term would be automatically assigned when a Creator adds one of their Product to a Collection.

#1758979

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

OK, I understand.

Maybe we can come at this from the other side then, and just use the post relationships and not use the product attributes.

If the key reason to use product attributes is so that you can later filter by collections, well, you can filter by related posts, and you could use that instead.

So if you have a many-to-many relationship between Collections and Products, you can create a View to display products and include a relationship filter for the Collections-Products relationship, so you get a dropdown that you can use to filter by Collection.

Have you tried that? If you are happy with that then I think it avoids the need for duplication.

#1759763

Hey Nigel,

Thanks for the follow-up and suggestion to use the post relationships.

This would probably work if all our products were displayed using Toolset Views.

However we use the native WooCommerce [products] shortcode for most of our listings and we've selected a 3rd-party plugin that integrates with WooCommerce shortcodes to filter our products (enlace oculto). This plugin provides many features like ajax refresh, custom term thumbnails, range filters, etc.

We also might want to allow a visitor browsing the "Baseball Caps" product category to filter the product list using the Collection "Summer 2020 by New Era". There are many pages on our website displaying a list of products and none of them use a Toolset View so we need a solution that'll integrate with the current implementation as far as possible.

I was just a bit confused in having both a WC Attribute using the slug "Collection" and a CPT with the same slug. Will we be running into any kind of trouble down the road?

Again thanks for your assistance.

All best,
B

#1760073

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

OK, understood.

You shouldn't use the same slug for a CPT and for a taxonomy because it can create confusion (for WordPress) when parsing URLs. You can give them the same name, but the slug must be different (even if the difference is as simple as 'collection' and 'collections').