Looper for related products

Hi there,
I’ve been trawling through lots of posts to find a solution for my problem, but can’t see one that’s relevant. I have developed a layout for a woocommerce product. In this I would like to use a looper and output my own styled Related Products. I have set up a provider on a row using this query string.

category_name={{dc:term:name}}&post_type=product&posts_per_page=3&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}

This should provide 3 related products, excluding the current product being viewed. When I set up a consumer for the column however, it seems the dynamic content {{dc:term:name}} is empty, so it returns 3 products of any category. I can’t work out why {{dc:term:name}} is not returning a value. Each product will have more than 1 category, they will generally have 1 parent category and 1 or more other categories. How do I ensure that I can access and am using the lowest level category that applies to a product please?

I will attach login details etc.

Hi @pmason,

Thanks for reaching out.
I would suggest you use the Related Product element which has similar options to show the related products and exclude the current one. I went ahead and added the Related Product element into another Layout, which can be used for reference purposes.

Screenshot-324-

Hope it helps.
Thanks

Hi there.
Thanks for taking a look.
However, I wanted to use my own looper so that I could keep the look consistent with the looper I use on the home page for New Arrivals. The layout of the default Related Products does not contain all the data I want to include either.
Can you please just help me to figure out the query string I need to use to get the correct products displayed?
Kindest regards.
Phil.

Hi Phil,

If that is the case and you need to use the Looper only, I would suggest you to go through the following thread which may help you on this.

Hope it helps.
Thanks

Hi there.
That’s one of the posts where I got the original query string from. As I stated earlier, the problem I have is that the dynamic content {{dc:term:slug}} doesn’t appear to be returning anything. Can you help with that please?
Kindest regards,
Phil.

Hello Phil,

I checked your site it seems that the same category products are rendering on the related product section. If you go to your product section on the backend and filter with category, it would list the product by category. Now if you view any of the products on the product details page the same category products are listed on the related product section. Please have a look at the screenshot in the secure note.

Hope it helps
Thanks

Hi @prakash_s.

This is very frustrating for me, especially as I have invested heavily in the PRO theme, but neither of you seem to be understanding the issue.

Yes, the Related Products available in Pro is working with the correct category, but I don’t want to use that. I want to use a looper so that I can have the data and display matching the looper I have set up on my home page for my New Arrivals. As I keep saying, I just need help ensuring that {{dc:term:slug}} returns the correct category slug when used on a single product page. If neither of you can help me, can this be passed on to someone more familiar with working with loopers please?

Kindest regards,

Phil.

Hello, butting in a bit in here because i actually had the SAME problem as @pmason is having and i would really like to find out why it doesnt work. We both followed the same exact post that @tristup mentioned yet it doesn’t work for us.

It almost like the DC content on the query string just doesnt load up.

Would really like if we could get a nice concrete answer here from the support team.

Cheers,
Jonathan

Hello Phil,

The {{dc:term:slug}} dynamic content will get the category slug of the current product and use this to return any other related products. If you want to display other products that is not of the same category, you will have to manually add it in your looper like:

category_name=clothing&post_type=product&posts_per_page=3&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}

I also have checked your homepage and you are using the Query Builder for the new arrivals. If you want to display the latest products instead of the related products, you should be using the same Query Builder in your looper provider instead.

Hope this helps.

Still not got this resolved. Just to summarise, when using a layout for a product page, {{dc:term:slug}} returns an empty string. So, you cannot use that dynamic content term in a query string e.g. category_name={{dc:term:name}}&post_type=product&posts_per_page=3&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}. Very disappointing as that means you cannot create a custom looper for Related Products.

Hi Phil,

I have tried the same Query String in the Single Product layout and found a similar problem. I suspect this could be a bug on the latest version, I will check and report it to the Issue Tracker so this issue will be queued for fixing to Plugin Author.

I would suggest you use the Related Product, which you are using currently.

Thanks

For those interested, here is the solution for this problem. After a lot of trial and error and referencing every thread I could find, I finally managed to achieve what I was looking for. The documentation and support for this is really very poor, but here’s the solution that worked for me.

  1. Added a new section with a looper provider set to Current Post Terms and Product Categories. Also switched on the looper consumer and set count to 1.

  2. Added a row with a looper provider set to Query String and used the following string and dynamic content, product_cat={{dc:terms:slug}}&post_type=product&posts_per_page=4&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}.

  3. Added a column with just the looper consumer switched on and set to All items. You can then fill the column with whatever you want to display.

Worked like a charm. Hope it helps someone else save hours of head scratching and banging it against a wall.

2 Likes

Hello @pmason,

Thanks for sharing the information

Have a great day!
Thanks

Have we had any update on rather or not this is a bug?

We are getting loads of mixed messages from the support crew, some say its not possible to use DC content on query stings and other say you can.

Would love it if we can get a more solid answer on this topic as this is a very commonly asked question.

Also thanks @pmason for sharing that out, unfortunately not sure if its due to the bug or anything else, but I haven’t been able to do it as you mention. Products do come up but they are way different from the original woocommerce related products.

Hi @Maratopia_Digital,

Reading the description from @pmason above, I would expect that to work. If you’re having trouble getting it working, my first thought would be placing {{dc:term:name}} in a text element somewhere as a test. It might be that the current term at that point in the page isn’t what you’re expecting.

To clarify, on Dynamic Content and Looper Providers here are a few notes:

  • Dynamic Content doesn’t work with Query Builder
  • Dynamic Content does work with Query String
  • Dynamic Content does not work automatically with Custom, but cs_dynamic_content can be called in the PHP function to process your parameters
  • With the JSON provider, if you supply a Dynamic Content statement instead of JSON it will try to resolve JSON data. You can’t actually put Dynamic Content in the JSON fields. This isn’t really useful anymore since we added the actual “Dynamic Content” provider type.

Hopefully this helps clear things up!

1 Like

Hey @alexander,

You were absolutely right on this! I had the custom post terms on offset=0 which was getting a very wide range category and not very specific to the product. When i put in the {{dc:term:name}} to see which categories it was pulling through I could then set an ideal offset to which category would be closely related to the product. Now it’s working quite nicely, even been able to put it to randomly show the product with orderby=rand, which is pretty neat!

Thank you for this detailed explanation on the Dynamic Content on Looper Provider really helps!

Hi @Maratopia_Digital,

Glad that we are able to help you.

Thanks

Apologies, there is a small typo in the query string here. The query string should be as follows (without the ‘s’ in {{dc:terms:slug}}), product_cat={{dc:term:slug}}&post_type=product&posts_per_page=4&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D={{dc:post:id}}.

1 Like

Hi @pmason,

Thanks for sharing it.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.