Steps to Change Product Image in Magento 2 Checkout Cart?
Today, we’re going to teach you guys how to change a product image in Magento 2 checkout cart page.
In case you didn’t know, Magento 2 checkout cart page is the intermediate step that proceeds to finalize a purchase. And the product image displayed on the Magento 2 checkout cart page provides customers with a quick overview of the product they’re about to purchase.
However, when a product has multiple colors, the image on the Magento 2 checkout cart page might not match the custom selection of a customer. This can ultimately create confusion and may lead to cart abandonment.
Fortunately, there is a solution for that. In this post, we’re going to show you exactly how to change a product image in your Magento 2 checkout cart page.
Step-by-Step Process to Change a Product Image in Magento 2 Checkout Cart Page
Please follow the below steps to learn how to change a product image in Magento 2 checkout cart page.
Step – 1
First of all, create a di.xml file in the app/code/Vendor/Extension/etc folder and paste the following code:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Checkout\Block\Cart\Item\Renderer"> <plugin name="product_image_checkout_cart" type="Vendore\Extension\Plugin\CheckoutCart\NewImage" sortOrder="1"/> </type> </config>
Step – 2
After that, create a NewImage.php file in the Vendor/Extension/Plugin/CheckoutCart folder and paste the following code:
<?php namespace Vendore\Extension\Plugin\CheckoutCart; class NewImage { public function afterGetImage($item, $result) { if(CONDITION) { $result->setImageUrl(IMAGE_URL); } return $result; } }
Final Note
And that’s about it! That’s all you need to do to change a product image in your Magento 2 checkout cart page.
We hope that you found this tutorial helpful. If you have any doubts, please ask them in the comments below.
And if you need our professional assistance, feel free to contact us anytime.