Magento add wishlist block to cart.phtml

Magento add wishlist block to cart.phtml

September 20, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento add wishlist block to cart.phtml

Integrating Wishlist into Magento Cart Page: A Step-by-Step Guide

As a new Magento developer, you might find it challenging to modify core functionality like displaying wishlists on the cart page. However, with some understanding of layout updates and block rendering, this task becomes straightforward.

Understanding the Current Structure

The default Magento installation separates the cart and wishlist functionalities into distinct pages located at /checkout/cart and /wishlist. The current cart.phtml file simply displays the items in the customer’s shopping cart without any reference to their wishlist.

Adding Wishlist to Cart Page

To integrate the wishlist with the cart page, you’ll need to follow these steps:

Step 1: Override the Default Cart Layout

Open your custom theme folder at app/design/frontend/<Vendor>/<ThemeName>. If it doesn’t exist, create a new folder structure matching Magento’s conventions.

Navigate to the checkout folder and create a new layout XML file called checkout_cart_index.xml.

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generate.xsd">
    <layout id="checkout_cart_index">
        <referenceBlock name="checkout.cart.items" after="-">
            <block class="Magento\Wishlist\Block\Catalog\Product\Viewer" template="Magento_Wishlist::catalog/product/viewer.phtml"/>
        </referenceBlock>
    </layout>
</layout>

In this layout update, we’re adding the Magento\Wishlist\Block\Catalog\Product\Viewer block to the cart items list. This viewer block is responsible for rendering the wishlist content.

Step 2: Override the Cart Viewer Template

Next, you’ll need to create a new template file that combines both the cart and wishlist information. Create a new directory structure under app/design/frontend/<Vendor>/<ThemeName>/template/Magento_Wishlist/catalog/product and add your custom viewer template called viewer.phtml.

Here’s a basic implementation of this file:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

use Magento\Framework\Pricing\Helper\Item as ItemPriceHelper;
use Magento\Wishlist\Model\WishlistFactory;

/** @var \Magento\Theme\Block\Html\Pager $block */
$block = $this->getLayout()->createBlock('Magento\Theme\Block\Html\Pager');
/** @var ItemPriceHelper $itemPriceHelper */
$itemPriceHelper = $this->helper(ItemPriceHelper::class);

In this template, you can use the wishlist factory to retrieve and display the customer’s wishlist items. You’ll need to loop through the wishlist items and render them using the appropriate Magento blocks.

Step 3: Refresh Your Static Content

After making these changes, make sure to refresh your static content by running:

php bin/magento setup:static-content:deploy -f

This command will generate the necessary JavaScript files and ensure that your layout updates are applied correctly.

Conclusion

Integrating wishlists into the cart page is a common customization in Magento. By leveraging the existing catalog/product/viewer.phtml template and applying proper layout updates, you can achieve this functionality without having to modify core files directly.

Remember, when working with Magento, it’s essential to follow best practices for overriding layouts and templates to ensure your changes are applied correctly across different environments and versions of the platform.

As a final note, if you’re looking to understand more about advanced customizations like creating new plugins or extending Magento models, I’d recommend checking out Laravel Company’s Magento Development Services. We specialize in helping businesses maximize their e-commerce potential through expert Magento development.

Checkout Catalog Themes Customers

Our network