Hi
On compare / wishlist (single product page) – if you add to wishlist or compare the text changes to whatever we set from within the settings of the widget – ie “Added to Wishlist / Remove from Wishlist” but when you’re on a product and let’s say the page refreshes; or they look around and come back – it reverts back to “Add to” instead of “Remove / View”.
How can we resolve this so it remembers that you’ve added THAT SPECIFIC product, so upon a return to that same product in the same browser session, it remembers what was added?
It’s kinda odd that it doesn’t allow more customisation and auto-flow as in –
1. Add to ->
2. Remove from ->
3. View ->
I could use js but surely if I can build a fix, I’m questioning why it’s not built-in?
Example –
jQuery(document).ready(function($){
// --- Wishlist Button Handling ---
$('.xstore-wishlist-btn').each(function(){
var $btn = $(this);
var productID = $btn.data('product-id');
// Check if product is already in wishlist
if (window.XStoreWishlist && window.XStoreWishlist.items && window.XStoreWishlist.items.includes(productID)) {
$btn.text('Remove from Wishlist').addClass('added');
}
});
// Wishlist click behavior: Add → Remove → View
$('.xstore-wishlist-btn').on('click', function(e){
e.preventDefault();
var $btn = $(this);
var productID = $btn.data('product-id');
if (!$btn.hasClass('added')) {
// Add to wishlist
$btn.text('Remove from Wishlist').addClass('added');
} else {
// Remove from wishlist
$btn.text('Add to Wishlist').removeClass('added');
}
});
// --- Compare Button Handling ---
$('.xstore-compare-btn').each(function(){
var $btn = $(this);
var productID = $btn.data('product-id');
// Check if product is already in compare list
if (window.XStoreCompare && window.XStoreCompare.items && window.XStoreCompare.items.includes(productID)) {
$btn.text('View Compare').addClass('added');
}
});
// Compare click behavior: Add → Remove → View
$('.xstore-compare-btn').on('click', function(e){
e.preventDefault();
var $btn = $(this);
var productID = $btn.data('product-id');
if (!$btn.hasClass('added')) {
$btn.text('Remove from Compare').addClass('added');
} else {
$btn.text('View Compare').addClass('added'); // or navigate to compare page if you want
}
});
});