Skip Navigation

[Resolved] Archive grouping products by taxo or tag without duplicates.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 11 months, 3 weeks ago.

Assisted by: Minesh.

Author
Posts
#2653843

Hello,

I need some help figuring out the logical way of doing this, or if it's even possible.

I've made this conditional look in the single product template:
hidden link

Basically checks the product_tag and shows all products with the same tag in a box, to display the multiple brand / prices. Works great.

What I would want to do is the same but for the archive posts, ie: category posts. The first and obvious issue is that the products will be duplicated. If I put a similar template in the category_archive of say, clutches, it will show all the diferent prices etc based on product_tag but it will also duplicate, since it's showing all products within the category.

I've thought of a couple ways, including using custom queries, Views API.

The way I thought to approach it was to use some php to recount which products have already been displayed and return null when they have already. Maybe using the #wpv_filter_force_template. But I'm not sure it would work.

I would like some help from the experts in figuring out the best approach asuming it's possible, before I set out to actually program every bit of code etc.

Thank you!

#2653939

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share taxonomy URL and tell me with example what product you want to display and what product that are duplicates you want to remove?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2654077

Hey Minesh,

It's not precisely a problem, I'm mostly looking towards help with the building logic.

The navigation of my site uses product_cat for the archives, those cats can be clutchs, brake parts, etc. If you look at the link I provided, you can see in the single post product I already have set up what I want to translate into an archive. In the link provided there are three separate products displayed with their prices, that is using a View that queries the product_tag and retrieves all products with that tag.

The thing with an archive of a product_cat is that it will show all products of that cat, so if I use a template that in turn uses a View to query the product_tag, I can obviously reproduce that same behaviour in the archive, but since all products of that category will be shown in the archive, the products will not so much duplicate in a strict sense, since it will show unique SKUs, but since I'm showing in a single product 'box' multiples products that have the same tag, it will propagate.

So:

SKU1's box will show, SKU2 & SKU3
then
SKU2's box will show, SKU1 & SKU3
then
SKU3's box will show, SKU1 & SKU2

Is it clear what I'm saying so far?

I was thinking of building custom code to monitor some of this, but before diving into coding I was hoping to get some feedback, since I'm not 100% sure what I'm trying to do is feasible.

#2654835

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I understand that you do not want to duplicate the product within the same tag/category on taxonomy archive and you have specific requirement about displaying the product matching the unique SKUs and/or price.

To filter the taxonomy archive query you can use the standard WordPress "pre_get_posts" hook.

You can not use "wpv_filter_force_template" hook as its not for use of archive, its for filtering the single post content template.

If you have multiple archive per term then you can switch the archive based on your desired condition using the hook:
- wpv_filter_force_wordpress_archive
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive

If you can help me with real life problem URL of your tags archive and tell me what products you want to include/display with that archive and what products you want to remove and based on what condition, once I review all those information I will be able to guide you in the right direction and tell you what would be the best possible workaround/solution in that case.

For that I will require admin access details and all the required information that you can share with few screenshots (if possible/required).

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2767442

Hey, I simply created a view that returned all products based on product_tag, included that view inside a template that was used as the archive-template.
Said view included a template that simply displayed sku, price some other fields and an add to cart.

After all that I removed duplicates with JS, it's actually very performant strangely, since we're filtering upward of 30k products at times.

One thing to keep in mind is using a high number of return products from the archive, I use 12 which works in filtering a lot of products and removing duplicates without messing with pagination.

the js in question (if you could do the formatting for the code I dont' know how in this chat):

document.addEventListener('DOMContentLoaded', () => {

let displayedTagsWithProductIds = JSON.parse(sessionStorage.getItem('displayedTagsWithProductIds')) || {};

const filterProducts = () => {

let productItems = document.querySelectorAll('#BlockMainSingle'); // Adjust the selector as needed, this would be the id from the div containing each product card in the archive

// First pass: Collect tags and their potential product IDs
let tagToProductMapping = {};
productItems.forEach(productItem => {
let tagElement = productItem.querySelector('#paFlexSingle > div:nth-child(2) > div > p'); // adjust selectors as needed
if (tagElement) {
let productId = tagElement.dataset.productArchiveId;
let productTags = tagElement.textContent.split(',')
.map(tag => tag.trim())
.filter(tag => tag !== '');

productTags.forEach(tag => {
if (!tagToProductMapping[tag]) {
tagToProductMapping[tag] = [];
}
tagToProductMapping[tag].push(productId);
});
}
});

// Second pass: Apply visibility logic
productItems.forEach(productItem => {
let tagElement = productItem.querySelector('#paFlexSingle > div:nth-child(2) > div > p'); // adjust selectors as needed
if (tagElement) {
let productId = tagElement.dataset.productArchiveId;
let productTags = tagElement.textContent.split(',')
.map(tag => tag.trim())
.filter(tag => tag !== '');

let shouldBeVisible = productTags.some(tag => {
if (tagToProductMapping[tag][0] === productId) {
// This product is the first in line for this tag, show it
return true;
}
return false; // This tag has another product to be displayed
});

productItem.style.display = shouldBeVisible ? '' : 'none';
}
});

sessionStorage.setItem('displayedTagsWithProductIds', JSON.stringify(displayedTagsWithProductIds));
};

filterProducts();

// Bind to AJAX pagination (adjust the event and selector as per your site's structure)
jQuery(document).on('js_event_wpv_pagination_completed', filterProducts);
jQuery(document).on('js_event_wpv_parametric_search_triggered', filterProducts);
jQuery(document).on('js_event_wpv_parametric_search_started', filterProducts);
jQuery(document).on('js_event_wpv_parametric_search_form_updated', filterProducts);
jQuery(document).on('js_event_wpv_parametric_search_results_updated', filterProducts);
});

It uses the events from toolset also to work with pagination and filters.

hidden link

Diego Walter Ricciardi confirmed that the issue was resolved on 2024-10-04 18:29:22.
This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.