Shopify Theme Development-如何以逗号分隔和货币显示产品价格

时间:2019-08-16 11:29:02

标签: collections shopify product currency

我试图提取一个“精选”的集合,然后针对每个提取的产品,如果产品成千上万种,我希望以货币和逗号分隔显示产品的价格。

这是我的代码,成功地从集合中提取了产品,但是我不知道,也找不到在产品循环中显示货币的相关文档。

{% if collections['featured-products'].products.size >= 1 %}

    {% for product in collections['featured-products'].products limit:3 %}

    <div class="featured-product">
        <div class="featured-product-image" style="background-image: url({{ product.featured_image | product_img_url: 'medium' }})"></div>

        <p class="featured-product-title">{{ product.title | escape }}</p>
        <p class="featured-product-price">{{ product.amount_with_comma_separator }}</p>

        <div class="product-buttons">

            {% include 'view-button' %}
            {% include 'add-to-cart-button' %}

        </div>
    </div>

    {% endfor %}

{% endif %}

我还使用了{{product.price}},它可以工作,但在成千上万时不使用相关货币或不显示逗号。

如果有人可以救我,那将非常好,因为Google在此实例中不是我的朋友。

谢谢杰森。

1 个答案:

答案 0 :(得分:1)

您正在寻找资金过滤器。这些过滤器允许您使用货币和小数等格式设置数字。您可以在Shopify管理员中设置货币格式,然后相应地使用过滤器。

Shopify Currency Formatting

您可以使用产品价格,然后应用所需的过滤器,例如

{{ product.price | money }}
{{ product.price | money_with_currency }}
{{ product.price | money_without_trailing_zeros }}

Shopify Money Filters