Keeping 'item' or 'items' in cart quantity
Closed this issue · 4 comments
richgcook commented
Is it possible to include 'item' or 'items' when the cart updates? I'm currently using {{ cart.item_count }} {{ cart.item_count | pluralize: 'item', 'items' }} in my theme but when it updates (add a product or click to view the cart drawer) it changes to 1 £48.00 (for example) whereas I had it before as 2 items £48
Any thoughts?
Cam commented
It sounds like you are using the ajax cart, so you will likely need to modify the ajax cart javascript too Timber/assets/ajax-cart.js.liquid
richgcook commented
Thanks @Cam.
I believe this is what I am after...
updateCountPrice = function (cart) {
if ($cartCountSelector) {
$cartCountSelector.html(cart.item_count).removeClass('hidden-count');
if (cart.item_count === 0) {
$cartCountSelector.addClass('hidden-count');
}
}
if ($cartCostSelector) {
$cartCostSelector.html(Shopify.formatMoney(cart.total_price, settings.moneyFormat));
}
};
I am unsure where cart.item_count
is called from?
canardos commented
Change:
$cartCountSelector.html(cart.item_count).removeClass('hidden-count');
to:
$cartCountSelector.html(cart.item_count + (cart.item_count === 1 ? ' item' : ' items')).removeClass('hidden-count');