cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 check if product is in wishlist

Magento2 check if product is in wishlist

Hi, I need to check if on catalog category page and product view page if the product is in wishlist. If in wishlist I need to add a different icon. Can somebody help me figure this out? thanks

5 REPLIES

Re: Magento2 check if product is in wishlist

When doing this, you'll want to avoid breaking the full page caching of the page. You'll want to find out what products are in the customer's wishlist via ajax and then store the results in a cookie/local storage for future use. E.g. https://magento.stackexchange.com/questions/144851/check-if-product-is-in-wishlist/144856#144856

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Magento2 check if product is in wishlist

can it be done any other way?


Tom Robertshaw wrote:

When doing this, you'll want to avoid breaking the full page caching of the page. You'll want to find out what products are in the customer's wishlist via ajax and then store the results in a cookie/local storage for future use. E.g. https://magento.stackexchange.com/questions/144851/check-if-product-is-in-wishlist/144856#144856


 

Re: Magento2 check if product is in wishlist

<?php if($_category_config['addtowishlist']): ?>
<?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
<a href="#"
class="action towishlist actions-secondary"
title="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
data-post='<?php echo $block->getAddToWishlistParams($_product); ?>'
data-action="add-to-wishlist"
role="button">
<span><?php echo __('Add to Wish List') ?></span>
</a>
<?php endif; ?>
<?php endif; ?>

 

Would like to change class inside ATAG if its not in wishlist, so any idea how to do it here on catalog product list page and also on catalog product view page.

Re: Magento2 check if product is in wishlist

There's no other way to do it without breaking full page cache or making that block always uncached which would degrade performance. As soon as you need the site to change based off a customers session, you need this kind of solution.

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Magento2 check if product is in wishlist

i would also like to add to wishlist and remove from wishlist from same place. what do i do?