【问题标题】:Change "Add to Cart" to "Choose Option" for variant product in collection page Shopify将集合页面 Shopify 中变体产品的“添加到购物车”更改为“选择选项”
【发布时间】:2021-02-10 13:01:45
【问题描述】:

我已设法在 Out of the Sandbox 的 Flex 主题中将“添加到购物车”按钮添加到我的收藏页面。但是,对于变体产品,当您单击添加到购物车时,它会自动将默认变体产品添加到购物车。我想更改此设置,以便在按钮上显示“选择选项”而不是“添加到购物车”,然后单击它会将您带到产品页面,然后您必须在将其添加到购物车之前选择变体。

添加到购物车按钮的代码是:

<form method="post" action="/cart/add">
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
<input type="submit" value="{% if product.variants.first.available%}Add to Basket{% else %}Out of Stock{% endif%}" class="button ajax-submit action_button button--add-to-cart" {% unless product.variants.first.available %}disabled{% endunless %} />
</form>

有人可以帮忙吗?

谢谢

【问题讨论】:

  • 试试这个tutorial它不会显示flex主题,但你应该在那里找到一个包含类似文件的主题,看看然后按照教程。

标签: shopify liquid


【解决方案1】:

这样的事情会起作用:

{% if product.available == false %}
    <span>Out of Stock</span>
{% elsif product.has_only_default_variant %}
    <form method="post" action="/cart/add">
        <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
        <input type="submit" value="Add to Basket" class="button ajax-submit action_button button--add-to-cart" />
    </form>
{% else %}
    <a href="{{ product.url }}">Choose option</a>
{% endif %}

【讨论】:

  • 太好了 - 谢谢。现在可以了。我已更改代码,以便选择选项和缺货显示在与添加到购物车相同的按钮中。
  • 我现在遇到的另一个问题是,在“产品”页面中,当您单击“添加到购物车”时,它会在按钮中显示一个 ✓ 符号以显示已添加产品,以及迷你购物车下拉显示购物车中的内容。但是,使用上面的代码,这只会将产品添加到购物车,而不会执行其他操作。知道如何让它也能做到这些吗?
  • 我需要仔细查看代码,但我认为您需要使用 JS 触发迷你车打开。这意味着您还需要使用 Cart API 添加到购物车:shopify.dev/docs/themes/ajax-api/reference/cart
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-19
  • 1970-01-01
  • 1970-01-01
  • 2013-05-07
相关资源
最近更新 更多