February 7, 2025
  • Access the admin section of your Shopify store.
  • Click “Online Store” on the sidebar and then choose “Themes.”
  • For the theme you want to change, select “Edit code” from the “Actions” drop-down menu.
  • In the left sidebar, find the “Snippets” folder and click to enlarge it.
  • To open it, locate the “product-template.liquid” file and click on it.
  • Find the section in the “product-template.liquid” file where the metafield should be added. You might use this space to display product information like the price or description.
  • Put the following code snippet there once you’ve found the right spot:

Metafields Using Upsell

{% assign product = product.selected_or_first_available_variant %}
{% assign metafields = product.metafields.namespace_key %}

Substitute your metafield’s actual namespace and key for namespace_key. If your metafield, for instance, has the namespace “upsell” and the key “recommended_products,” the code snippet would seem as follows:

{% assign metafields = product.metafields.upsell.recommended_products %}

You may get the value of your metafield by using the metafields variable after inserting the code snippet. You can, for instance, add the following code to display the metafield value:

{{ metafields }}

You should save the “product-template.liquid” file after making modifications.

You should be able to add a metafield and use Shopify’s upsell capability to get its value by following these instructions. Keep in mind to modify the namespace and key values to suit the setting of your particular metafield.

1 thought on “Shopify Metafields Using Upsell

Leave a Reply

Your email address will not be published. Required fields are marked *