【问题标题】:Shopify adding the product price inside the add to cart buttonShopify 在添加到购物车按钮中添加产品价格
【发布时间】:2020-10-21 09:00:32
【问题描述】:

我想在“添加到购物车”按钮中添加价格。

如您所见,我可以在按钮中添加价格,但是当我更改变体时,它会消失。 (网址会随着选择不同的变体而变化)

GIF that shows the problem

有什么建议吗?

目前的代码是:

<button
      {% if product.empty? %}type="button"{% else %}type="submit"{% endif %}
      name="add"
      id="AddToCart-{{ section_id }}"
      class="btn btn--full add-to-cart{% if enable_dynamic_buttons %} btn--secondary{% endif %}"
      {% unless current_variant.available %} disabled="disabled"{% endunless %}>
      <span id="AddToCartText-{{ section_id }}"  data-default-text="{{ default_text }}">
        {{ button_text }} {{ current_variant.price | money }}
      </span>
    </button>

【问题讨论】:

    标签: javascript shopify liquid


    【解决方案1】:

    答案是使用Javascript。当您第一次渲染页面时,Liquid 渲染会在按钮上放置一个价格。但是,当您更改变体时,不会呈现 Liquid,因此您只能使用 Javascript。我敢肯定,在 10 多年之后,您现在可以找到一些可以满足您需要的示例。

    当变体发生变化时,通常会运行一些“知道”变体的 Javascript,因此它就是价格,因此唯一的挑战是找到按钮上的旧价格,并覆盖它。通常是简单的东西。

    【讨论】:

    • 嗨,大卫。我花了几个小时寻找类似的问题,但我什么也没找到。你有解决这个问题的想法吗?我 product.liquid 的代码在这里:paste.org/111482
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-07
    • 2017-01-03
    相关资源
    最近更新 更多