在 Shopify 中隐藏空购物车

Hiding empty cart in Shopify

我试图在购物车为空时隐藏我的购物车,并在 header.liquid 文件中找到了我的购物车代码片段

<a href="/cart" class="site-header__cart">
{% include 'icon-cart' %}
<span class="visually-hidden">{{ 'layout.cart.title' | t }}</span>
<span class="icon__fallback-text">{{ 'layout.cart.title' | t }}</span>
{% if cart.item_count > 0 %}
<div id="CartCount" class="site-header__cart-count">
<span>{{ cart.item_count }}</span>
<span class="icon__fallback-text medium-up--hide">{{ 'layout.cart.items_count' | t: count: cart.item_count }}</span>
</div>
{% endif %}
</a>

我也尝试过使用我在此处找到的代码 (https://ecommerce.shopify.com/c/ecommerce-design/t/hide-cart-checkout-button-when-cart-is-empty-115075)

{% if cart.item_count != 0 %}

这两个都不适合我,有什么建议吗?

您可以使用此代码,如果这有助于您解决问题,请告诉我们:

{% if cart.item_count > 0 %} your html here {% endif %}

如果您的页面在添加到购物车期间没有刷新,如果您的主题使用 ajax 添加到购物车功能,您还需要对 js 进行一些更改。

谢谢