liquid - Shopify: How do I create a new button that will redirect to the Product page?
I'm new here and also fairly new to coding in Liquid/JSON. I'm working on a Shopify project where I need to create a new button placed right below the product price. The button will read "Learn More" and once clicked it will direct the user to the product page. I believe I located the right liquid file and the code needs to be added here so it will appear in the Featured Collection section of the theme.
I'm not creating a new Featured Collection section from scratch, but altering the theme's existing code.
{% render 'section--featured-collection' with
heading: section.settings.title,
collection: collections[section.settings.collection],
per_row: section.settings.per_row,
rows: section.settings.rows,
aspect_ratio: section.settings.aspect_ratio
%}
{% schema %}
{
"name": "t:sections.featured_collection.name",
"class": "inline-section",
"templates": ["404", "article", "blog", "cart", "collection", "list-collections",
"customers/account", "customers/activate_account", "customers/addresses",
"customers/login", "customers/order", "customers/register",
"customers/reset_password", "gift_card", "index", "page", "product", "search"],
"settings": [
{
"id": "collection",
"type": "collection",
"label": "t:sections.featured_collection.settings.collection.label"
},
{
"id": "title",
"type": "text",
"label": "t:sections.featured_collection.settings.title.label",
"default": "Featured collection"
},
{
"type": "range",
"id": "per_row",
"label": "t:sections.featured_collection.settings.per_row.label",
"min": 2,
"max": 4,
"step": 1,
"default": 3
},
{
"type": "range",
"id": "rows",
"label": "t:sections.featured_collection.settings.rows.label",
"min": 1,
"max": 3,
"step": 1,
"default": 1
},
{
"id": "aspect_ratio",
"type": "select",
"label": "t:shared.aspect_ratio.label",
"options": [
{ "label": "t:shared.aspect_ratio.options.natural", "value": "natural" },
{ "label": "t:shared.aspect_ratio.options.square", "value": "square" },
{ "label": "t:shared.aspect_ratio.options.landscape", "value": "landscape" },
{ "label": "t:shared.aspect_ratio.options.portrait", "value": "portrait" }
],
"default": "natural"
}
],
"presets": [
{
"name": "Featured collection",
"category": "Collection",
"settings": {}
}
]
}
{% endschema %}
Any help with this would be much appreciated and a HUGE help! Thanks!
Answer
Solution:
Inside yoursection--featured-collection
snippet, when looping over products of the featured collection, it's pretty standard to refer to each product's url using theproduct.url
property.
{% for product in collection.products %}
<!-- Typically more information, like product image, title and price -->
<a href="{{ product.url }}">Learn More</a>
{% endfor %}
You can find more information on the product properties in the Shopify doc (https://shopify.dev/api/liquid/objects/product).
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.