How to remove items from wishlist collection in magento

How to remove items from wishlist collection in magento

July 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to remove items from wishlist collection in magento

Solution: Deleting Wishlist Items in Magento Without Manual Refresh

Are you facing issues when deleting wishlist items in your Magento store? Does refreshing the page become necessary to see the changes after deletion? You’re not alone! This common problem occurs due to how Magento handles form submissions and cookie data. In this post, we’ll explore why this issue arises and provide a comprehensive solution that eliminates the need for manual page refreshes.

Understanding the Underlying Problem

The core of your issue lies in how you’re currently handling wishlist item deletion and redirection after the form submission. Here are two key points to note:

  1. When you submit a form in Magento, the server processes the request, performs the deletion, but the client (browser) still holds onto the old HTML content until it’s explicitly told otherwise.
  2. Using header("refresh:0.0000000000001;", $url); only triggers a refresh on the client-side after an infinitesimally small delay, which is why you observe a slight lag before the page updates.

The Elegant Solution

To solve this problem without relying on manual page refreshes, we’ll leverage Magento’s built-in JavaScript functionality and modify your form submission process. Here’s a step-by-step approach:

  1. Remove the refresh header: Begin by commenting out or removing the header() function from your controller action.
// Remove this line (or comment it out)
// header("refresh:0.0000000000001;", $url);
  1. Enable AJAX for the form submission: By default, Magento enables AJAX for forms with id="form-ajax" and class="form-ajax" attributes. Modify your wishlist deletion form to include these identifiers.
<form id="wishlist-delete-form" method="post">
    <!-- Your checkboxes and other form elements -->
    <div class="button-set">
        <button type="submit" title="<?php echo $this->__('Delete Selected Items') ?>" onclick="deleteWishlistItems()" class="scalable button delete"><span><span><?php echo $this->__('Delete Selected Items') ?></span></span></button>
    </div>
</form>

<script type="text/javascript">
    function deleteWishlistItems() {
        var form = document.getElementById("wishlist-delete-form");
        form.submit();
    }
</script>
  1. Modify the controller action: In your controller, ensure that you’re returning an empty JSON response after successful item deletion.
public function deleteAction()
{
    // Your existing code for processing deleted items

    $this->getResponse()->setHeader('Content-type', 'application/json');
    return new Varien_Object();
}
  1. Test the solution: Save your changes and visit the wishlist page on your Magento storefront.

When you submit the form to delete wishlist items, Magento will now automatically update the page content without requiring a manual refresh. The server processes the deletion request, and the client-side immediately reflects the changes thanks to the built-in AJAX functionality.

This solution provides an efficient way to handle wishlist item deletion while ensuring a seamless user experience. It eliminates the need for unnecessary page reloads and improves the overall performance of your Magento store.

If you’re looking for more in-depth guides on Magento development, feel free to explore our comprehensive Magento tutorials at Laravel Company. We cover various aspects of Magento development, from theme customization to extension creation.

Errors JavaScript CLI

Our network