I want to add custom code in my catalog search page. I don't want to override product/list.phml file .

But, Just display my custom code in catalog search result page after product price. How to add it?

enter image description here

I have used this plugin code.It's working in only list product. But, when I search that product I can't find content of my custom phtml.

di.xml :

<type name="Magento\Catalog\Block\Product\ListProduct">
        <plugin name="vendor-module-category-timer" type="VendorName\ModuleName\Plugin\CategoryTimer" sortOrder="16"/>

CategoryTimer.php :

public function aroundGetProductDetailsHtml(
    \Magento\Catalog\Block\Product\ListProduct $subject,
    \Closure $proceed,
    \Magento\Catalog\Model\Product $product
) {
    return "call2";
  • my guess is the data you render in your plugin are not available in search page. I'd need to see the code that works to give a better answer? Commented Nov 24, 2018 at 9:03

2 Answers 2


You need to create <virtualType> plugin for that. Try this below code :

Add this code in your di.xml file :

<virtualType name="Magento\CatalogSearch\Block\SearchResult\ListProduct">
        <plugin name="vendorName_moduleName_VirtualPlugin"
                type="vendorName\moduleName\Plugin\MyPlugin" />

And then you need to create this below plugin file :

public function aroundGetProductDetailsHtml(
    \Magento\Catalog\Block\Product\ListProduct $subject,
    \Closure $proceed,
    \Magento\Catalog\Model\Product $product
) {
    return "call2";

I hope it will helpful for you..

  • It's not working Commented Nov 27, 2018 at 17:56
  • Sorry.. I forgot to change plugin code. Commented Nov 27, 2018 at 18:00
  • Please check my updated answer. Commented Nov 27, 2018 at 18:00
  • Okay. I'm checking and inform you. Commented Nov 27, 2018 at 18:09

Create Magento_CatalogSearch folder under your custom theme

Add Magento_CatalogSearch\layout\catalogsearch_result_index.xml and put below code:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="catalogsearch.product.addto">
            <block class="Magento\Framework\View\Element\Template" name="product.data.custom" template="Magento_CatalogSearch::custom.phtml" after="catalogsearch.product.addto" />

Add custom.phtml file with your content/text/code


Change Magento_CatalogSearch to YoucPackage_YourModule in case you are trying code in custom module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.