Change product image placeholder based on product – Magento 2

We need to override the below two functions in vendor/magento/module-catalog/Helper/Image.php

Below function change the placeholder image in the home page, category page, product page.

public function getPlaceholder($placeholder = null)
{
	$product = $this->getProduct();
	if($product->getName() == "Test Name") // here your condition
	{
		// logic to retrieve new url
		return $new_palceholder_url;
	}
        ...............//remining magento core codes
}

Below function change the placeholder image in cart page.

public function getUrl()
{
	$product = $this->getProduct();
	if($product->getName() == "Test Name") // here your condition
	{
		// logic to retrieve new url
		return $new_palceholder_url;
	}
        ...............//remining magento core codes
}

I hope it helps. Thanks.

About Bilal

I'm a software programmer, I handle Magento2 modifications at any level.

View all posts by Bilal →

One Comment on “Change product image placeholder based on product – Magento 2”

Leave a Reply

Your email address will not be published. Required fields are marked *