1
votes

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?

1

1 Answers

3
votes

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>