Adding link to download file from metafield

Topic summary

A user is implementing code to display a download link for a ZIP file stored in a Shopify order metafield (order.metafields.custom.order_mockup_file).

Original Issue:

  • The initial code snippet appears corrupted or improperly formatted, making it difficult to parse the intended implementation.
  • The user wants customers to download customized files attached to their orders via metafields.

Proposed Solution:

  • Another user suggests corrected code syntax using proper Liquid templating.
  • The solution checks if the metafield exists and isn’t blank before rendering the download link.
  • Key elements include: conditional {% if %} statements, proper anchor tag structure with download attribute, and correct metafield reference syntax.

Status: The discussion appears resolved with a working code example provided, though the original poster hasn’t confirmed implementation success.

Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

Hi,

I am using the following code to display a link to download a zip file added to a meta field

{% comment %}Custom Code to Show Custom File Uploaded to the customer order{% endcomment %}
            <td>  {% if order.metafields.custom.order_mockup_file %}
              <a href="{{ order.metafields.custom.order_mockup_file.file}}" download>Download Customized File</a><br>
              {% endif %}</td>
            
            {% comment %}END of Custom Code to Show Custom File Uploaded to the customer order{% endcomment %}

but it keeps giving me the HTML file, not the zip file?

@CreativeMind202 it’s been a while since this question was posted but for anyone else looking, I think the right code would be:

{% comment %}Custom Code to Show Custom File Uploaded to the customer order{% endcomment %}
            {% if order.metafields.custom.order_mockup_file != blank %}
              Download Customized File

              {% endif %}
            
            {% comment %}END of Custom Code to Show Custom File Uploaded to the customer order{% endcomment %}