{"id":1786,"date":"2021-06-09T03:03:41","date_gmt":"2021-06-09T03:03:41","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/change-product-image-in-magento-2-checkout-cart\/"},"modified":"2025-07-16T17:42:54","modified_gmt":"2025-07-16T12:12:54","slug":"change-product-image-in-magento-2-checkout-cart","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/change-product-image-in-magento-2-checkout-cart\/","title":{"rendered":"How to Change Product Image in Magento 2 Checkout Cart"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2\u00a0checkout 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, when the product has multiple colors and options the image might not match the desired custom selection of the customer.<br>Moreover, when a store owner wants to give a free product based on a condition, and that product belongs to the customer\u2019s selected configured one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In that case, what if a store owner needs to display an image of the main product in the free one?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Any solution? Here is the quick solution. Apply the below method to&nbsp;<em><strong>change product image in Magento 2 checkout cart<\/strong><\/em>!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Change Product Image in Magento 2 Checkout Cart<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Use the below code in the&nbsp;<strong>di.xml<\/strong>&nbsp;file at&nbsp;<strong>app\/code\/Vendor\/Extension\/etc<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;type name=\"Magento\\Checkout\\Block\\Cart\\Item\\Renderer\">\n    &lt;plugin name=\"product_image_checkout_cart\" type=\"Vendore\\Extension\\Plugin\\CheckoutCart\\NewImage\" sortOrder=\"1\"\/>\n&lt;\/type><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create the&nbsp;<strong>NewImage.php<\/strong>&nbsp;file at&nbsp;<strong><strong>Vendor\/Extension\/Plugin\/CheckoutCart<\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendore\\Extension\\Plugin\\CheckoutCart;\n\nclass NewImage\n\n{\n\n    public function afterGetImage($item, $result)\n\n    {\n\n     if(CONDITION) {\n\n     $result->setImageUrl(IMAGE_URL);\n\n     }\n\n     return $result;\n\n    }\n\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2\u00a0checkout cart page is the intermediate point that proceeds to finalize the purchase. The product image displayed on the checkout cart page gives the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1786"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":18053,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions\/18053"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}