向购物车页面添加“继续购物”链接

您可以将继续购物链接添加到购物车页面,使客户在将产品添加到购物车后可轻松返回浏览产品。您可以选择添加一个链接,用于将客户定向回目录页面、您的主页或他们之前查看的最后一个产品系列页面。

继续购物

向购物车页面添加“继续购物”链接

若要向您的购物车页面添加继续购物链接,请执行以下操作:

  1. Sections 目录中,点击 cart-template.liquid。如果您的模板中没有此文件,则点击 Templates 目录中的 cart.liquid

  2. 通过搜索 name="checkout" 的文件来查找结账按钮的代码。结账按钮的代码行因模板而异,但会如下所示:

<button type="submit" id="checkout" name="checkout" class="btn">
  {{ 'cart.general.checkout' | t }}
</button>
  1. 下一步是粘贴新的代码行以创建继续购物链接。您粘贴的代码将取决于您希望链接转到的页面:
<a href="/collections/all" title="Continue shopping">Continue shopping</a>
### For a link that goes to your home page

To add a link that goes to your home page, paste the following code on a new line either before or after the code for the **Checkout** button:
<a href="/" title="Continue shopping">Continue shopping</a>
### For a link that goes to the last collection viewed

To add a link that goes to the last collection viewed, paste the following code on a new line either before or after the code for the **Checkout** button:
<a
  id="continue-shopping"
  href=""
  title="Continue shopping">
  Continue shopping
</a>
  1. 点击保存。如果您添加了指向目录页面或主页的链接,则操作已完成。如果您添加了指向上一个查看的产品系列的链接,则需要向您的模板代码中添加一些 JavaScript。然后继续按照后续步骤操作。

  2. Layout 目录中,点击 theme.liquid

  3. 在文件底部附近查找结束 </body> 标记。将以下代码粘贴到结束 </body> 标记上方:

<script>
  if(Storage !== undefined) {

    var defaultLink = "/collections/all";

    {% if template contains 'collection' %}
      sessionStorage.collection = "{{ collection.url }}";
    {% endif %}

    {% if template contains 'cart' %}
      if( !sessionStorage.collection ) {
        sessionStorage.collection = defaultLink;
      }
      document.getElementById("continue-shopping").href = sessionStorage.collection;
    {% endif %}

    }
</script>
  1. 点击保存

添加按钮样式(可选)

如果您使用免费的 Shopify 模板,则可以将样式应用于继续购物链接,使它呈现按钮的外观。通过向按钮链接的代码中添加类属性,您可以使您的按钮与模板中其他按钮的样式匹配。所有免费 Shopify 模板都对主按钮样式使用相同的类名称,并且大多数此类模板对辅助按钮样式使用相同的类名称。

若要向“继续购物”链接应用主要按钮样式,请执行以下操作:

将属性 class="btn" 添加到您已粘贴的代码行中,以便添加继续购物链接。您的代码应如下所示:

<a href="/collections/all" title="Continue shopping" class="btn">
  Continue shopping
</a>

若要向“继续购物”链接应用辅助按钮样式,请执行以下操作:

备注:添加此类对 Boundless 没有影响。

如果您使用的是 Supply 以外的免费模板,请将属性 class="btn--secondary" 添加到您已粘贴的代码行中,以便添加继续购物链接。您的代码应如下所示:

<a href="/collections/all" title="Continue shopping" class="btn--secondary">
  Continue shopping
</a>

如果您使用 Supply,请将属性 class="btn-secondary" 添加到您已粘贴的代码行,以便添加继续购物链接。您的代码应如下所示:

<a href="/collections/all" title="Continue shopping" class="btn-secondary">
  Continue shopping
</a>

准备好开始使用 Shopify 进行销售了吗?

免费试用