How to add a cart icon with add to cart button in catalog category page in magento 2?

How to add a cart icon with add to cart button in catalog category page in magento 2?

August 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to add a cart icon with add to cart button in catalog category page in magento 2?

Adding a Cart Icon with Add-to-Cart Button in Magento 2 Category Page

Are you looking to enhance your Magento 2 store’s user experience by adding an “Add to Cart” button directly on the category page? In this guide, we’ll walk through the steps required to achieve this.

Understanding the Default Magento Behavior

By default, Magento separates the shopping experience into distinct stages. The product listing pages (category pages) allow customers to browse and filter products, while the individual product detail pages provide more information and facilitate the addition of items to the cart.

However, many merchants prefer a more seamless shopping flow where customers can add products directly from the category page. This approach offers several benefits, including reduced friction in the purchasing process and potentially increased conversion rates.

Overriding the Default Behavior

To modify this behavior, we need to override Magento’s default product listing template. Here’s how:

1. Create a Custom Theme

The first step is to create or use an existing custom theme for your store. This will allow us to safely modify the templates without affecting the core files.

If you haven’t already, create a new theme by copying an existing one (e.g., Luma) and renaming it according to your preference:

cd /path/to/your/magento-installation/app/design/frontend
cp -R Magento/blank .
mv blank My_Custom_Theme

2. Override the Product Listing Template

Next, we need to override the Magento_Catalog module’s template file responsible for rendering the product list:

cd /path/to/your/magento-installation/app/design/frontend/My_Custom_Theme/Magento Catalog/catalog_product_list.html

In this file, find the line where the “Add to Cart” button is rendered (around line 130):

<div class="actions-primary">
    <a href="<?php /* @escapeNotVerified */ echo $block->getProductUrl($product) ?>" title="<?php /* @escapeNotVerified */ echo $productName; ?>">
        <?php if ($block->isSaleable($product)): ?>
            <button type="button" class="action tocart primary">
                <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
            </button>
        <?php else: ?>
            <p class="no-display"><?php /* @escapeNotVerified */ echo __('Sold Out') ?></p>
        <?php endif; ?>
    </a>
</div>

3. Move the “Add to Cart” Button to the Category Page

To add the “Add to Cart” button directly to the category page, we’ll use a combination of JavaScript and jQuery. First, create a new file named add-to-cart.js in your theme’s JavaScript folder:

cd /path/to/your/magento-installation/app/design/frontend/My_Custom_Theme/js
touch add-to-cart.js

In this file, add the following code:

require(['jquery'], function($) {
    $(document).ready(function() {
        $('.product-item-info .actions-primary').each(function(index, element) {
            var productId = $(this).find('.product-id').text();
            $(this).append('<button type="button" class="action tocart primary add-to-cart-category">'+
                '<span>Add to Cart</span>'+
            '</button>');
        });

        $('.add-to-cart-category').click(function() {
            var productId = $(this).parent().find('.product-id').text();
            $.post("/rest/V1/carts/mine/items", { "cart_item": { "sku": productId, "qty": 1 } })
                .done(function(data) {
                    alert("Product added to cart!");
                });
        });
    });
});

Don’t forget to require this JavaScript file in your theme’s main JavaScript file (usually named requirejs-config.js):

var config = {
    map: {
        '*': {
            addToCartCategory: 'My_Custom_Theme/js/add-to-cart'
        }
    }
};

Conclusion

By following the steps outlined above, you should now have successfully added an “Add to Cart” button directly on your Magento 2 category page. This enhancement can significantly improve the user experience and potentially boost your store’s conversion rates.

Remember that customizing Magento’s core templates is generally not recommended unless necessary. Always test your changes thoroughly and consider using a dedicated development environment before deploying them to your live site.

For more advanced customizations and technical guidance, I recommend checking out Laravel Company, where our team of experienced developers offers expert services for Magento projects of all sizes.

Happy coding!

Magento 2 Checkout Catalog Themes

Our network