Shopify如何增加PDF下载功能(规格书,产品目录,保修卡,说明书)
在 Shopify 中,为每个产品提供 PDF 下载链接(如规格书、手册、保修卡等)是一种非常实用的做法,能帮助用户快速了解产品详细信息,提升用户体验和转化率。本文将手把手教你如何在 Shopify 产品页面中增加 PDF 下载功能,包括前端模板编写、Metafields 使用、语言国际化、样式优化等关键环节。
一、准备工作:使用 Metafields 存储 PDF 文件
Shopify 支持通过自定义字段(Metafields)为每个产品附加额外信息,如 PDF 文件链接。
- 进入 Shopify 后台 > 设置(settings) > 自定义数据(Metafields and metaobjects) > 产品(Products);

添加以下字段:

specsheet
(规格书)catalogues
(目录)manual
(说明书)warranty
(保修卡)specsheet
(规格书)catalogues
(目录)manual
(说明书)warranty
(保修卡)
字段类型选择「文件」file;

为每个产品上传对应 PDF 文件。
二、添加 HTML 渲染逻辑
在 main-product.liquid
中搜索{%- when 'description' -%} 并在该代码段下面添加如下代码,判断是否上传了 PDF,并动态渲染下载列表:
{%- when 'downloads' -%}
<!--downloads-->
{% assign specsheet = product.metafields.custom.specsheet.value.url %}
{% assign catalogues = product.metafields.custom.catalogues.value.url %}
{% assign warranty = product.metafields.custom.warranty.value.url %}
{% assign manual = product.metafields.custom.manual.value.url %}
{% if specsheet or catalogues or manual or warranty %}
<div class="tt-collapse-block prpage-tabs">
{% comment %} <h2 class="tt-title-small">Downloads</h2> {% endcomment %}
<div class="pdp-documents__list">
{% if specsheet %}
<div>
<a href="{{ specsheet }}" target="_blank" class="pdf-link" style="color: inherit; text-decoration: none;">
<img src="https://cdn.shopify.com/s/files/1/0602/3708/6977/files/pdf.jpg?v=1742629859" alt="Specsheet Pdf Icon" width="80" height="80"><span class="img-text">Spec Sheet</span></a >
</div>
{% endif %}
{% if catalogues %}
<div>
<a href="{{ catalogues }}" target="_blank" class="pdf-link" style="color: inherit; text-decoration: none;">
<img src="https://cdn.shopify.com/s/files/1/0602/3708/6977/files/pdf.jpg?v=1742629859" alt="User Manual Pdf Icon" width="80" height="80"><span class="img-text">Catalogues</span></a >
</div>
{% endif %}
{% if manual %}
<div>
<a href="{{ manual }}" target="_blank" class="pdf-link" style="color: inherit; text-decoration: none;">
<img src="https://cdn.shopify.com/s/files/1/0602/3708/6977/files/pdf.jpg?v=1742629859" alt="User Manual Pdf Icon" width="80" height="80"><span class="img-text">Manual</span></a >
</div>
{% endif %}
{% if warranty %}
<div>
<a href="{{ warranty }}" target="_blank" class="pdf-link" style="color: inherit; text-decoration: none;">
<img src="https://cdn.shopify.com/s/files/1/0602/3708/6977/files/pdf.jpg?v=1742629859" alt="Warranty Pdf Icon" width="80" height="80"><span class="img-text">Warranty</span></a >
</div>
{% endif %}
</div>
</div>
{%- endif -%}
三、解决常见错误提示
✅ 1. Missing translation 报错
如果你在 schema 中使用了 t:
语言翻译方式,需要在 locales/en.default.json
文件中找到
"products": {
"product": {
"add_to_cart": "Add to cart",
"choose_options": "Choose options",
"choose_product_options": "Choose options for {{ product_name }}",
"description": "Description",
在下方添加翻译内容:
"downloads": "Downloads",
如有英语语言支持,在en.default.schema.json可找到
"description": {
"name": "Description"
},
在下方添加:
"downloads": {
"name": "Downloads"
},
✅ 2. Missing width and height on <img>
标签
Shopify Theme Check 要求所有 <img>
标签必须显式设置 width
和 height
,避免页面抖动和性能问题。
修复方式:
<img src="…" alt="…" width="80" height="80">
四、美化样式:去除链接颜色和下划线
你可以为 .pdf-link
添加 CSS 样式去除蓝色链接和下划线:
在theme.css或者base.css添加
/* 下载downloads */
.pdp-documents__list {
margin-bottom: 20px; /* 底部间距 */
overflow: hidden; /* 清除浮动 */
}
.pdp-documents__list::after {
content: "";
display: block;
clear: both;
}
.pdp-documents__list div {
width: calc(25% - 10px); /* 每个 div 占据 1/4 宽度 */
float: left; /* 启用浮动 */
margin: 5px; /* 设置块与块之间的间距 */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.pdp-documents__list img {
width: 100%; /* 确保图片的宽度适应容器 */
height: auto; /* 保持图片的纵横比 */
margin-bottom: 5px; /* 图片和文本之间的间距 */
}
.img-text {
display: flex;
align-items: center;
justify-content: center;
}
五、去添加Downloads block块
online store——themes——customize——切换到product——default product,左侧找到description,添加downloads模块
总结
通过使用 Metafields + Block 模板 + 多语言支持 + 样式优化,Shopify 商家可以优雅地为每个产品添加 PDF 下载区域。这不仅提高了用户对产品的理解,也提升了站点的专业度和信任度。
如你希望进一步封装成可复用的 snippet 或独立 Section,我也可以提供完整组件版本,欢迎留言交流。
如需部署服务或定制开发支持,欢迎联系我(微信:kaituo52099)。