Home Forums WoodMart support forum Remove product from Wishlist on second click

Remove product from Wishlist on second click

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #480135

    mohsen.amra.70
    Participant

    Hello
    I would likne to remove product from Wishlist on second click On withlist icon. Based on woodmart theme when you click on wishlist icon the product has been added to wishlist list and after that when for second time you click on the whishlist icon you can see the whishlist page and redirect to the whishlist page.

    So we can only abale to remove the product from the wishlist when go to the whishlis page. In this way I want to remove product from whishlist without sending user to whishlist page and remove product from wishlist on second click. Is it possible?

    Here is my code. But it does not working.

    
    jQuery(document).ready(function($) {
        var clickCount = 0;
        var clickTimeout;
    
        $('.wd-wishlist-btn a').on('click', function(e) {
            e.preventDefault();
    
            var $this = $(this);
            var productId = $this.data('product-id');
    
            clickCount++;
    
            if (clickCount === 1) {
                clickTimeout = setTimeout(function() {
                    clickCount = 0;
                    addToWishlist(productId);
                }, 300);
            } else if (clickCount === 2) {
                clearTimeout(clickTimeout);
                clickCount = 0;
                removeProductFromWishlist(productId);
            }
        });
    
        function addToWishlist(productId) {
            $.ajax({
                url: woodmart_settings.ajaxurl,
                data: {
                    action: 'woodmart_add_to_wishlist',
                    product_id: productId
                },
                dataType: 'json',
                method: 'GET',
                success: function(response) {
                    if (response) {
                        $('.wd-header-wishlist .wd-tools-count').text(response.count);
                        $('.wd-wishlist-btn a[data-product-id="' + productId + '"]').addClass('added');
                    } else {
                        console.log('Something went wrong while adding the product to the wishlist.');
                    }
                },
                error: function() {
                    console.log('Error: Unable to add the product to the wishlist.');
                }
            });
        }
    
        function removeProductFromWishlist(productId) {
            $.ajax({
                url: woodmart_settings.ajaxurl,
                data: {
                    action: 'woodmart_remove_from_wishlist',
                    product_id: productId
                },
                dataType: 'json',
                method: 'GET',
                success: function(response) {
                    if (response) {
                        $('.wd-header-wishlist .wd-tools-count').text(response.count);
                        $('.wd-wishlist-btn a[data-product-id="' + productId + '"]').removeClass('added');
                    } else {
                        console.log('Something went wrong while removing the product from the wishlist.');
                    }
                },
                error: function() {
                    console.log('Error: Unable to remove the product from  the wishlist.');
                }
            });
        }
    });
    #480188

    Artem Temos
    Keymaster

    Hello,

    Thank you so much for purchasing our theme and contacting our support center.

    Sorry, but additional code customizations like that are out of our theme support scope.

    Kind Regards
    XTemos Studio

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)