I want to display just wishlist count like wishlist (2) in top bar, how can I remove the word "items" or "item"
4 Answers
You can override the phtml: Theme_Root/Magento_Wishlist/templates/link.phtml
Instead this:
<span data-bind="text: wishlist().counter" class="counter qty"></span>
You can do this:
<span data-bind="text: wishlist().items.length" class="counter qty"></span>
-
I'm wondering is it worked for you? For me its not working console generates error, but weird part is after reload page error disappear!! Mar 14, 2020 at 19:40
-
-
-
E.g I have 5 Items in wishlist after doing as you said, it shows me 3 items Feb 11, 2021 at 11:49
you can remove it from
if you have no theme installed you can go to this and change the 1 item and %1 items.
vendor/magento/module-catalog/i18n/en_US.csv or
if you have a theme installed you can go to this location and do that.
app/design/frontend/Magento/<theme>/i18n/en_US.csv
-
thanks! but if i change "%1 items" to "%1" in en_US.csv it will change every where it found "%1 items". is there any other way?– WaqarAug 31, 2017 at 10:15
-
@waqar this is not used at more places so I think it will not affect your site. I personally replaced it and didn't see changes.You can go ahead. Aug 31, 2017 at 10:26
You can also edit counter generated phrase.
Look at the file in:
vendor/magento/module-wishlist/CustomerData/Wishlist.php
on line 84 you will see:
protected function createCounter($count)
{
if ($count > 1) {
return __('%1 items', $count);
} elseif ($count == 1) {
return __('1 item');
}
return null;
}
You only have to override that method in your custom module.
For more info on how to do that this, look the following:
-
1Please correct the path in your answer. It's "CustomerData" folder. /vendor/magento/module-wishlist/CustomerData/Wishlist.php Dec 21, 2018 at 6:41
You can use magento default way, just need to add simple regex for it.
Replace :
span data-bind="text: wishlist().counter" class="counter qty"></span
With :
span data-bind="text: wishlist().counter.replace(/[^0-9]+/g, '')" class="counter qty"></span