Hi i'm not developer so please help. i'm trying to change 'My Wish List' to 'wishlist' and wanna remove 'items'
My Wish List 2 items - wishlist 2
To change the label for 'My Wish List' to 'wishlist' , go to vendor/magento/module-wishlist/i18n/your_language.csv (i think there will be en_us only) And change:
"My Wish List","My Wish List"
to
"My Wish List","wishlist"
Okay, so if want to change as in the screenshot, goes to the same file and change this as you want.
"%1 items","%1 items"
to
"%1 items","%1"
This will implement the change that you want, also you have to do in the line before that is "1 item","1 item"
and remove the second item if you want to remove in case that there is only 1 item in the cart.
If you make the site multilanguage, don't forget to make the correct translations of this or this will appear in the other languages.
You dont wanna write a preference if you can write a plugin like. You can download the module from this link https://mage2gen.com/load/31b0b02d-c02e-47ae-b6e1-bbd967930509 make sure to replace the plugin with code below.
namespace [Vendor]\Wishlist\Plugin\Magento\Wishlist\CustomerData;
class Wishlist
{
/**
* @var \Magento\Wishlist\Helper\Data
*/
private $wishlistHelper;
/**
* Wishlist constructor.
* @param \Magento\Wishlist\Helper\Data $wishlistHelper
*/
public function __construct(
\Magento\Wishlist\Helper\Data $wishlistHelper
) {
$this->wishlistHelper = $wishlistHelper;
}
/**
* {@inheritdoc}
*/
public function afterGetSectionData(
\Magento\Wishlist\CustomerData\Wishlist $subject,
$result
) {
$result['counter'] = $this->wishlistHelper->getItemCount();
return $result;
}
}
Here is best way to archive this task.
'%1 items' text is coming from [createCounter] function from Wishlist class we only need to create preference for this.
\Magento\Wishlist\CustomerData\Wishlist
1.di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Wishlist\CustomerData\Wishlist" type="\Namespace\Modulename\CustomerData\Wishlist" />
</config>
Whishlist.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Namespace\Modulename\CustomerData;
class Wishlist extends \Magento\Wishlist\CustomerData\Wishlist
{
public function __construct(
\Magento\Wishlist\Helper\Data $wishlistHelper,
\Magento\Wishlist\Block\Customer\Sidebar $block,
\Magento\Catalog\Helper\ImageFactory $imageHelperFactory,
\Magento\Framework\App\ViewInterface $view
) {
parent::__construct($wishlistHelper, $block, $imageHelperFactory, $view);
}
protected function createCounter($count)
{
if ($count > 1) {
return __('%1', $count);
} elseif ($count == 1) {
return __('1');
}
return null;
}
}
This one is the best way rather than changing in language file.