Deepak Kamat
Deepak Kamat

Reputation: 1980

How to get product URL from a `product` input in Shopify Theme

I am developing a Shopify theme and in one of the section I am adding a setting that let's the user choose a product from their shop

In the schema I have this

  {
     "type": "product",
     "id": "product_order",
     "label": "Product to link"
  }

In the HTML I am doing this

<a href="{{section.settings.product_order.url}}">Order this product</a>

However the href is always empty. I tried selecting different products but no use.

outputting section.settings.product_order prints the product title.

Am I using the product setting input incorrectly?

Upvotes: 1

Views: 10654

Answers (1)

Prabin Sapal
Prabin Sapal

Reputation: 346

Hey try the following code it will help you and it works fine in my project.

{%- assign product = all_products[section.settings.product_order] -%}
<a href="{{ product.url}}">Order this product</a>

or you can also write that code in a single line:

<a href="{{ all_products[section.settings.product_order].url}}">Order this product</a>

Upvotes: 3

Related Questions