Skip to content

Shopify为购物车礼品包装选项创建代码片段步骤

Shopify为购物车礼品包装选项创建代码片段步骤
厦门商城系统开发

创建代码片段

若要为礼品包装选项创建代码片段,请执行以下操作:

PC:

  1. 在 Shopify 后台中,转到在线商店 > 模板
  2. 找到要编辑的模板,然后点击操作 > 编辑代码
  3. 在 Snippets 目录中点击添加新片段
  4. 将您的代码片段命名为 gift-wrapping,然后点击创建代码片段。您的代码片段文件将在代码编辑器打开。
  5. 在此步骤中,您需要将一些代码粘贴到新的 gift-wrapping 代码片段文件中。您粘贴的代码取决于您要如何向客户收取礼品包装服务的费用:

苹果系统:

  1. 在 Shopify 应用中,轻触商店
  2. 销售渠道部分中,轻触在线商店
  3. 轻触 Manage themes(管理模板)。
  4. 找到要编辑的模板,然后点击操作 > 编辑代码
  5. 在 Snippets 目录中点击添加新片段
  6. 将您的代码片段命名为 gift-wrapping,然后点击创建代码片段。您的代码片段文件将在代码编辑器打开。
  7. 在此步骤中,您需要将一些代码粘贴到新的 gift-wrapping 代码片段文件中。您粘贴的代码取决于您要如何向客户收取礼品包装服务的费用:

安卓系统:

  1. 在 Shopify 应用中,轻触商店
  2. 销售渠道部分中,轻触在线商店
  3. 轻触 Manage themes(管理模板)。
  4. 找到要编辑的模板,然后点击操作 > 编辑代码
  5. 在 Snippets 目录中点击添加新片段
  6. 将您的代码片段命名为 gift-wrapping,然后点击创建代码片段。您的代码片段文件将在代码编辑器打开。
  7. 在此步骤中,您需要将一些代码粘贴到新的 gift-wrapping 代码片段文件中。您粘贴的代码取决于您要如何向客户收取礼品包装服务的费用:

为礼品包装添加固定费率

粘贴以下代码并保存

{% if linklists.gift-wrapping.links.size > 0 and linklists.gift-wrapping.links.first.type == 'product_link' %} 
   

             

   

          >          >   

 
 {% assign id = linklists.gift-wrapping.links.first.object.variants.first.id %} {% assign gift_wraps_in_cart = 0 %} {% for item in cart.items %} {% if item.id == id %} {% assign gift_wraps_in_cart = item.quantity %} {% endif %} {% endfor %}   {% else %} 

   You attempted to add a gift-wrapping script to your shopping cart, but it   won't work because you don't have a link list with handle   gift-wrapping which, in turn, contains a link to your   gift-wrapping product. Please review the steps outlined   here   >. 

 {% endif %}

添加费用并乘以订单中的产品数

使用此选项时,如果订单有三件产品,则礼品包装费用将乘以 3。粘贴以下代码并保存

{% if linklists.gift-wrapping.links.size > 0 and linklists.gift-wrapping.links.first.type == 'product_link' %} 
   

             

   

          >          >   

 
 {% assign id = linklists.gift-wrapping.links.first.object.variants.first.id %} {% assign gift_wraps_in_cart = 0 %} {% for item in cart.items %} {% if item.id == id %} {% assign gift_wraps_in_cart = item.quantity %} {% endif %} {% endfor %} {% assign items_in_cart = cart.item_count | minus: gift_wraps_in_cart %}   {% else %} 

   You attempted to add a gift-wrapping script to your shopping cart, but it   won't work because you don't have a link list with handle   gift-wrapping which, in turn, contains a link to your   gift-wrapping product. Please review the steps outlined   here   >. 

 {% endif %}

在购物车模板中包含代码片段

若要在购物车模板中包括礼品包装代码片段,请执行以下操作:

  1. 在 Sections 目录中,点击 cart-template.liquid。如果您的模板中没有 cart-template.liquid,请点击 Templates 目录中的 cart.liquid
  2. 查找代码中的结束  标记。在结束  标记上方的新行中,粘贴以下代码:
{% render 'gift-wrapping' %}
  1. 点击保存

Shopify商户官网原文详情:

Create a code snippet

To create a code snippet for the gift-wrap option:

PC:

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Snippets directory, click Add a new snippet.
  4. Name your snippet gift-wrapping and click Create snippet. Your snippet file will open in the code editor.
  5. In this step, you will paste some code into your new gift-wrapping snippet file. The code you paste depends on how you want to charge your customers for the gift wrapping service:

iPhone:

  1. From the Shopify app, tap Store.
  2. In the Sales channels section, tap Online Store.
  3. Tap Manage themes.
  4. Find the theme you want to edit, and then click Actions > Edit code.
  5. In the Snippets directory, click Add a new snippet.
  6. Name your snippet gift-wrapping and click Create snippet. Your snippet file will open in the code editor.
  7. In this step, you will paste some code into your new gift-wrapping snippet file. The code you paste depends on how you want to charge your customers for the gift wrapping service:

Android:

  1. From the Shopify app, tap Store.
  2. In the Sales channels section, tap Online Store.
  3. Tap Manage themes.
  4. Find the theme you want to edit, and then click Actions > Edit code.
  5. In the Snippets directory, click Add a new snippet.
  6. Name your snippet gift-wrapping and click Create snippet. Your snippet file will open in the code editor.
  7. In this step, you will paste some code into your new gift-wrapping snippet file. The code you paste depends on how you want to charge your customers for the gift wrapping service:

Add a flat rate charge for gift wrapping

  1. Paste the following code and Save:
{% if linklists.gift-wrapping.links.size > 0 and linklists.gift-wrapping.links.first.type == 'product_link' %} 
   

             

   

          >          >   

 
 {% assign id = linklists.gift-wrapping.links.first.object.variants.first.id %} {% assign gift_wraps_in_cart = 0 %} {% for item in cart.items %} {% if item.id == id %} {% assign gift_wraps_in_cart = item.quantity %} {% endif %} {% endfor %}   {% else %} 

   You attempted to add a gift-wrapping script to your shopping cart, but it   won't work because you don't have a link list with handle   gift-wrapping which, in turn, contains a link to your   gift-wrapping product. Please review the steps outlined   here   >. 

 {% endif %}

Add a charge that is multiplied by the number of products in the order

  1. With this option, if there are three products in the order, then the gift wrap charge will be multiplied by three. Paste the following code and Save:
{% if linklists.gift-wrapping.links.size > 0 and linklists.gift-wrapping.links.first.type == 'product_link' %} 
   

             

   

          >          >   

 
 {% assign id = linklists.gift-wrapping.links.first.object.variants.first.id %} {% assign gift_wraps_in_cart = 0 %} {% for item in cart.items %} {% if item.id == id %} {% assign gift_wraps_in_cart = item.quantity %} {% endif %} {% endfor %} {% assign items_in_cart = cart.item_count | minus: gift_wraps_in_cart %}   {% else %} 

   You attempted to add a gift-wrapping script to your shopping cart, but it   won't work because you don't have a link list with handle   gift-wrapping which, in turn, contains a link to your   gift-wrapping product. Please review the steps outlined   here   >. 

 {% endif %}

Include the snippet in your cart template

To include the gift-wrapping snippet in your cart template:

  1. In the Sections directory, click cart-template.liquid. If your theme doesn’t have a cart-template.liquid, then click cart.liquid in the Templates directory.
  2. Find the closing  tag in the code. On a new line above the closing  tag, paste the following code:
{% render 'gift-wrapping' %}
  1. Click Save.

    码刀科技(www.lekshop.cn)是国内知名企业级电商平台提供商,为企业级商家提供最佳的电商平台搭建(多种模式电商平台搭建:B2B/B2B2C/B2C/O2O/新零售/跨境等)、平台管理系统开发及互联网采购解决方案服务, 联系客服了解更多.

    电子商务网站建设的重要性和好处