I want to add custom notices directly behind every price on product detail and category pages. On product detail page this works fine with layout.xml:
<referenceContainer name="product.info.price"> <block before="product.info.stock.sku" after="product.price.final" class="..." name="after_price" as="after.price" template="..."/> </referenceContainer>
But actually that doesn't work for category pages. If I look into
Magento\Catalog\Block\Product\ListProduct which is the block on the category page, there is a function called
getProductPrice() which is called for price rendering. Internally it calls
getPriceRender() which calls a block from layout which renders the price:
So I thought I just create a
catalog_category_view.xml layout file with the following content:
<referenceBlock name="product.price.render.default"> <block class="..." before="category.product.type.details.renderers" template="..."/> </referenceBlock>
But unfortunately this is not the solution, it doesn't work. I thought the reason is that
product.price.render.default is added dynamically as it only can be found on product detail page's layout xml files and not category layout files. But I can't find where it is added. And why does my layout file not work?
I don't want to overwrite the template
Magento_Catalog::product/list.phtml as different themes will overwrite my changes.