尊时凯龙

shopify向产品页面添加尺寸图表之代码片段设置步骤

2022/03/07

自建站

导航到代码编辑器

PC:

  1. Shopify 后台中,转到在线商店 > 模板

  2. 找到要编辑的模板,然后点击操作 > 编辑代码

苹果系统:

  1. 在 Shopify 应用中,轻触商店

  2. 销售渠道部分中,轻触在线商店

  3. 轻触 Manage themes(管理模板)。

  4. 找到要编辑的模板,然后点击操作 > 编辑代码

安卓系统:

  1. 在 Shopify 应用中,轻触商店

  2. 销售渠道部分中,轻触在线商店

  3. 轻触 Manage themes(管理模板)。

  4. 找到要编辑的模板,然后点击操作 > 编辑代码

选择以下内容之一,然后创建尺寸图表代码片段

  • Site wide

  • Product type

  • Product vendor

备注:选择“网站宽度”会在具有尺寸选项的所有产品页面上显示尺寸图表。

创建尺寸图表代码片段

  1. 在 Snippets 目录中点击添加新片段

  2. 将代码片段命名为 size-chart,然后点击创建代码片段:

  1. 将以下内容复制到您的 size-chart 代码片段中:

   
     ×     {{ pages.size-chart.content }}   
 
  

备注:需要针对模板 Simple 和 Minimal 的 CSS 样式执行一些更改。

如果您使用的是 Simple 模板,请将从 .trigger-pop-up 直到  上方的内容替换为以下代码:

.trigger-pop-up {   margin: 10px 0 10px 8px;   width: 50%; } @media only screen and (max-width: 749px) {   .pop-up-content,   .size-chart-content table {     width: 100%;   }   .size-chart-content th,   .size-chart-content td {     padding: 10px;   }   .trigger-pop-up {     width: 100%;   } }

如果您要使用 Minimal 模板,请在结束  标记上方添加以下代码:

@media only screen and (min-width: 750px) {   .trigger-pop-up {     width: 50%;   } }

将尺寸图表代码片段添加到您的 theme.liquid 中

  1. 在 Layout 目录中,点击打开您的 theme.liquid 文件。

  2. 找到结束  标记。在结束  标记正上方粘贴以下代码:

{% if request.page_type == 'product' %}     {% if product.options contains 'Size' %}         {% render 'size-chart' %}     {% endif %} {% endif %}

添加尺寸图表按钮

  1. 在 Sections 目录中,点击打开 product-template.liquid 文件,如果没有 product-template.liquid 文件,则点击打开 product.liquid 文件。

  2. 将以下代码粘贴到添加到购物车按钮上方:

{% if product.options contains 'Size' %}     See Size Chart {% endif %}

“添加到购物车”按钮的代码通常以 

更多

 \u003C/pre>\u003Cp>备注:需要针对模板 Simple 和 Minimal 的 CSS 样式执行一些更改。\u003C/p>\u003Cp>如果您使用的是 Simple 模板,请将从 \u003Ccode>.trigger-pop-up\u003C/code> 直到 \u003Ccode>\u003C/code> 上方的内容替换为以下代码:\u003C/p>\u003Cpre>.trigger-pop-up {   margin: 10px 0 10px 8px;   width: 50%; } @media only screen and (max-width: 749px) {   .pop-up-content,   .size-chart-content table {     width: 100%;   }   .size-chart-content th,   .size-chart-content td {     padding: 10px;   }   .trigger-pop-up {     width: 100%;   } }\u003C/pre>\u003Cp>如果您要使用 Minimal 模板,请在结束 \u003Ccode>\u003C/code> 标记上方添加以下代码:\u003C/p>\u003Cpre>@media only screen and (min-width: 750px) {   .trigger-pop-up {     width: 50%;   } }\u003C/pre>\u003Ch3>将尺寸图表代码片段添加到您的 theme.liquid 中\u003C/h3>\u003Col class=\" list-paddingleft-2\">\u003Cli>\u003Cp>在 \u003Cstrong>Layout\u003C/strong> 目录中,点击打开您的 \u003Ccode>theme.liquid\u003C/code> 文件。\u003C/p>\u003C/li>\u003Cli>\u003Cp>找到结束 \u003Ccode>\u003C/code> 标记。在结束 \u003Ccode>\u003C/code> 标记正上方粘贴以下代码:\u003C/p>\u003C/li>\u003C/ol>\u003Cpre>{% if request.page_type == 'product' %}     {% if product.options contains 'Size' %}         {% render 'size-chart' %}     {% endif %} {% endif %}\u003C/pre>\u003Ch3>添加\u003Cstrong>尺寸图表\u003C/strong>按钮\u003C/h3>\u003Col class=\" list-paddingleft-2\">\u003Cli>\u003Cp>在 \u003Cstrong>Sections\u003C/strong> 目录中,点击打开 \u003Ccode>product-template.liquid\u003C/code> 文件,如果没有 \u003Ccode>product-template.liquid\u003C/code> 文件,则点击打开 \u003Ccode>product.liquid\u003C/code> 文件。\u003C/p>\u003C/li>\u003Cli>\u003Cp>将以下代码粘贴到\u003Cstrong>添加到\u003Ca class=\"ll-inlink\" href=\"http://www.cuodiao.com/article_wiki/32-40219.html\" target=\"_blank\">购物车\u003C/a>\u003C/strong>按钮上方:\u003C/p>\u003C/li>\u003C/ol>\u003Cpre>{% if product.options contains 'Size' %}     See Size Chart {% endif %}\u003C/pre>\u003Cp>“添加到购物车”按钮的代码通常以 \u003Ccode>