How to Change Product Image in Magento 2 Checkout Cart
Magento 2 checkout cart page is the intermediate point that proceeds to finalize the purchase. The product image displayed on the checkout cart page gives the customer a quick overview of the items they are about to purchase.
However, when the product has multiple colors and options the image might not match the desired custom selection of the customer.
Moreover, when a store owner wants to give a free product based on a condition, and that product belongs to the customer’s selected configured one.
In that case, what if a store owner needs to display an image of the main product in the free one?
Any solution? Here is the quick solution. Apply the below method to change product image in Magento 2 checkout cart!
Method to Change Product Image in Magento 2 Checkout Cart
- Use the below code in the di.xml file at app/code/Vendor/Extension/etc
12345678<?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> - Create the NewImage.php file at Vendor/Extension/Plugin/CheckoutCart
1234567891011121314151617181920212223<?phpnamespace Vendore\Extension\Plugin\CheckoutCart;class NewImage{public function afterGetImage($item, $result){if(CONDITION) {$result->setImageUrl(IMAGE_URL);}return $result;}}
That’s it!
If you have any doubts regarding this post, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Thank You.
Related Post – How to Display Simple Product Image for Configurable Product Image in Magento 2 Mini Cart and Cart
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
Hi there,
How would the Image in the Checkout Order Summary be changed?
Hey Christopher,
You will have to create plugin to change image in order summary.