I've created a plugin to override getProductPrice()
method of Magento\Catalog\Block\Product\ListProduct
class.
This is my app/code/vendorName/moduleName/etc/di.xml:
<?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\Catalog\Block\Product\ListProduct">
<plugin name="vendorName_moduleName_Plugin" type="vendorName\moduleName\Plugin\MyPlugin" />
</type>
</config>
and this plugin class (app/code/vendorName/moduleName/Plugin/MyPlugin.php):
<?php
namespace vendorName\moduleName\Plugin;
class MyPlugin
{
public function afterGetProductPrice(\Magento\Catalog\Block\Product\ListProduct $product, $result)
{
return $result.'<input type="hidden" class="my-class" />';
}
}
It works fine when a category page is called but it doesn't override methods when I try to search a product.
Why?