1

I am new to Magento 2 and been wondering how to remove wishlist counter text.

I had tried generating a language pack using this command:

bin/magento i18n:collect-phrases -o "app/design/frontend/vendor/theme/i18n/en_US.csv" app/design/frontend/vendor/theme

in the newly generated files with 2 columns, I changed

%1 items

to

%1

I also tried replicating the one on Magento_Wishlist then put it in my custom theme but it does not work either.

Also, I tried this accepted solution but still no luck.

Thanks.

  • do you need to remove from header dropdown ? – hweb87 May 21 '18 at 10:36
  • @hweb87 No. I repositioned my Wishlist but I didn't remove any of its elements. I just wanted to remove the text in the counter because I will style it as a badge(like facebook notification count). – user67757 May 21 '18 at 10:59
1

Could you please try this :

"%1 items","%1"

Then clear cache and deploy :

php bin/magento clear:cache
php bin/magento setup:static-content:deploy
  • I already did that but it doesn't work. – user67757 May 22 '18 at 10:13
0

Did you try to specify the module in your language pack?

Like this

"%1 items","%1",module,Magento_Wishlist

Then flush cache and reload your page

  • I haven't tried that since the csv file that was generated only has 2 columns and I don't know which module does each phrases belong. – user67757 May 22 '18 at 10:13
0

I already figured out how to remove "items" in wishlist counter.

Instead of modifying the translation pack, I extended

Magento/Wishlist/CustomerData/Wishlist

to my custom module then override the function createCounter(), remove the text "items" in "%1 items"

protected function createCounter($count)
    {
        if ($count > 1) {
            return __('%1', $count);
        } elseif ($count == 1) {
            return __('1');
        }
        return null;
    }
0

Although I agree with Daniele that it is better to use translation dictionary, it is useful to know other possible methods:

– you can override createCounter function in Vendor/Module/CustomerData/Wishlist.php

/**
* Create button label based on wishlist item quantity
*
* @param int $count
* @return \Magento\Framework\Phrase|null
*/
protected function createCounter($count)
{
    return $count;
}

– you can update link template ( by default it is view/frontend/templates/link.phtml ) and change

<span data-bind="text: wishlist().counter" class="counter qty"></span>

to

<span data-bind="text: wishlist().counter.replace(/[^0-9]+/g, '')" class="counter qty"></span>

More information about working with Magento 2 Wishlist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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