Adding specific related products to a product page just got easier 🎉.
Shopify recently added two new features that make this process a lot more straightforward and user friendly for the merchant.
- List values for product metafields
- The new product_list section input setting
Prior to these we could use metafields, but we'd have to explain how to create metafields with namespacing and finding the product handle to merchants if they wanted to be able to edit/add them. This also made the process a little brittle, prone to spelling errors or changes to the product handle.
List values for the product metafield
Shopify has recently provided us with a new metafield paradigm. We can now add metafields directly to Shopify objects like Product or Variant directly in the product edit page.
We also have access to a whole bunch of new types of values we can create in the metafield including files, booleans, and lists.
Here's a quick Metafield reference.
Creating a product list metafield
To create a new metafield go to Settings > Metafields
, then choose Products for the object you'd like to put the metafield on. You'll then click Add definition and add the name, namespace, and description. You'll then select the content type. For this, we'll want to choose reference.
![](https://p62.tr2.n0.cdn.getcloudapp.com/items/d5u9nA6l/059aee79-3acc-47a5-81ed-a9466b403e13.png?v=5a779c62ad36bde082137530ab1d0179)
A reference is an existing Shopify object, and here you'll be able to choose from Page, Product, or Product Variant.
You'll also see a new option when you click on Product. A checkbox for Accept list values. This let's the user add multiple products to this one metafield 🙌.
![](https://p62.tr2.n0.cdn.getcloudapp.com/items/4guKenPZ/9480690c-5177-4d91-89e2-86714fbd7467.png?v=dc64ae1f59bdb70cc5c1ca6f5606960e)
Once that's done, go to a product and at the bottom of the page you'll be able to add the products to the metafield.
![](https://p62.tr2.n0.cdn.getcloudapp.com/items/lluEdNe9/749e6f8d-b70b-42fa-b24d-1d40468bf3e2.png?v=1544cf52d7cd7a3157ce1c2308561d91)
Then to display products we loop over the metafield value and access the product object as normal.
Note that the syntax is product.metafields.[[metafield namespace]].[[metafield name]].value
.
Recommended Products
{% assign recommended_products = product.metafields.my_fields.rec_products.value %}
{% for product in recommended_products %}
-
{{ product.featured_image | image_url: width: 400 | image_tag: loading: 'lazy' }}
{{product.title}}
{% endfor %}
![](https://p62.tr2.n0.cdn.getcloudapp.com/items/RBunZlAX/38cd55de-6af6-4e82-afa5-476c54c32a39.png?source=viewer&v=0046bc1d959087243a6e1283b814eefc)
The new product_list section input setting
But wait ✋, there's more!
Shopify has also provided us with a new section input type: product_list. Here's the reference.
The syntax is quite simple. Just add a new option to you section settings that looks like this.
{
"type": "product_list",
"id": "rec_product_list",
"label": "Rec Product List"
}
🔥Hot Tip: Here's a really simple intro to sections and here's the Shopify docs.
This will allow the merchant to choose the products right from the theme editor. Of course, if they choose products like this, they'll be the same products across all product pages.
However, you'll notice the connect dynamic source icon. This will allow you to connect this field to the metafield product list we just made.
![](https://p62.tr2.n0.cdn.getcloudapp.com/items/geumyAYK/695ff4b8-fa53-48a7-90df-8fd533fc83de.png?v=f66191b9cab73b103d7d15b6c0be873e)
Why? you might ask would we create a section, when we were already able to achieve the same results above?
Well, the section gives the merchant more flexibility in where they can put it and with Sections Everywhere, the merchant could put the section on the homepage with static data and on the product pages with dynamic content. Less coding for you, more options for the merchant - win win 🏆
🔥Hot Tip: If you want to get a little more fancy with the UX, here's a post on using Vue.js for related products.