3

I want to display just wishlist count like wishlist (2) in top bar, how can I remove the word "items" or "item"

1
  • can you please upload your code here? Aug 31, 2017 at 9:12

4 Answers 4

5

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>
4
  • 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!!
    – anonymous
    Mar 14, 2020 at 19:40
  • Worked for me thanks. May 5, 2020 at 6:53
  • Thanks @David It's working. Jun 15, 2020 at 8:21
  • E.g I have 5 Items in wishlist after doing as you said, it shows me 3 items Feb 11, 2021 at 11:49
3

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

2
  • 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?
    – Waqar
    Aug 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
2

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:

How to override customerData folder's file in magento 2?

1
  • 1
    Please correct the path in your answer. It's "CustomerData" folder. /vendor/magento/module-wishlist/CustomerData/Wishlist.php Dec 21, 2018 at 6:41
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.