M2 – How to change Wishlist icon color after product added to Wishlist

My code:

appdesignfrontendZeromy_themeMagento_Wishlisttemplatescatalogproductviewaddtowishlist.phtml

<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ // @codingStandardsIgnoreFile /** @var MagentoWishlistBlockCatalogProductViewAddToWishlist $block */ ?> <?php if ($block->isWishListAllowed()) : ?> <?php $_product = $block->getProduct(); ?> <?php $isAdded = $this->helper('MagentoWishlistHelperData')->getWishlistItemCollection()->addFieldToFilter('product_id', $_product->getId())->count(); ?> <?php if($isAdded): ?> <a href="javascript:void(0)" class="action towishlist already-added" data-action="add-to-wishlist"><span><?= $block->escapeHtml(__('Added to Wish List')) ?></span></a> <?php else: ?> <a href="#" class="action towishlist" data-post='<?= /* @noEscape */ $block->getWishlistParams() ?>' data-action="add-to-wishlist"><span><?= $block->escapeHtml(__('Add to Wish List')) ?></span></a> <?php endif; ?> <?php endif; ?> <script type="text/x-magento-init"> { "body": { "addToWishlist": <?= /* @noEscape */ $block->getWishlistOptionsJson() ?> } } </script> 

CSS:

appdesignfrontendZeromy_themeMagento_Wishlistwebcss_extend.less

.action.towishlist.already-added{color: #ff0000 !important;} 

After item added to wishlist the wishlist icon color not update.

submitted by /u/aveeva7
[link] [comments]