Liquid, JavaScript, themes, sales channels
Hello everyone!
Awesome community you guys have going on here!
I am hoping someone can help me with the following problem: I have inserted a "back to collection" button on my product page. This button basically checks the collection and the href sends the user back to that collection. However, if a product is accessed through the "product suggestions" at the bottom of the page, the button disappears. The collection also doesnt appear in the URL path (obviously).
My question is: is there some way for me to make sure the button always appears and sends the user back to the right collection? Perhaps I can define the destination of the button based on a product's tags (I imagine they are stored in some array that is accessible)? Or perhaps even parse the name of the collection from the product name, by following the folling naming scheme. Product P in Collection C name = "C P". If I could parse the first character, I would be able to return to that particular collection.
I might be overcomplicating this, but I am at a loss, and I am new to liquid!
Thank you!
Regards,
Jan
Solved! Go to the solution
This is an accepted solution.
You can actually return the url, you don't need the title:
{% for collection in product.collections %}
<a href="{{ collection.url }}">Back to Collection</a>
{% endfor %}
How about using the product.collections attribute to get the collections that the product belongs to and add the collection title to the button link url?
Obviously if the product belongs to more than one collection it would be more complicated, you'll get more than one title returned.
{% for collection in product.collections %}
<a href="https://www.your-shop-name/{{ collection.title }}>Back to collection</a>
{% endfor %}
This is an accepted solution.
You can actually return the url, you don't need the title:
{% for collection in product.collections %}
<a href="{{ collection.url }}">Back to Collection</a>
{% endfor %}
I didnt think it would work with the array of collections, but it did! Thank you!
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024