Skip to content

Change price template only for product on product page and not for other sections like related products sections

I was able to change the price design for only product page using the solution in this link

Change price template only for product view page?

My code:
In catalog_product_view.xml file I have added this code in the body tag

<block class="MagentoFrameworkPricingRender" name="product.price.render.default">
        <arguments>
            <argument name="price_render_handle" xsi:type="string">blanco_catalog_product_prices</argument>
            <argument name="use_link_for_as_low_as" xsi:type="boolean">true</argument>
            <!-- set "override" configuration settings here -->
        </arguments>
    </block>

And I have created a new XML file blanco_catalog_product_prices.xml inside my custom module and here is the content.

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
<block class="MagentoFrameworkPricingRenderRendererPool" name="render.product.prices">
    <arguments>
        <argument name="default" xsi:type="array">
            <item name="default_render_class" xsi:type="string">MagentoCatalogPricingRenderPriceBox</item>
            <item name="default_render_template" xsi:type="string">Magento_Catalog::product/price/default.phtml</item>
            <item name="default_amount_render_class" xsi:type="string">MagentoFrameworkPricingRenderAmount</item>
            <item name="default_amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
            <item name="prices" xsi:type="array">
                <item name="special_price" xsi:type="array">
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/special_price.phtml</item>
                </item>
                <item name="tier_price" xsi:type="array">
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/tier_prices.phtml</item>
                </item>
                <item name="final_price" xsi:type="array">
                    <item name="render_class" xsi:type="string">MagentoCatalogPricingRenderFinalPriceBox</item>
                    <item name="render_template" xsi:type="string">Custom_BlancoLayout::product/price/final_price.phtml</item>
                </item>
                <item name="custom_option_price" xsi:type="array">
                    <item name="amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
                </item>
                <item name="configured_price" xsi:type="array">
                    <item name="render_class" xsi:type="string">MagentoCatalogPricingRenderConfiguredPriceBox</item>
                    <item name="render_template" xsi:type="string">Magento_Catalog::product/price/configured_price.phtml</item>
                </item>
            </item>
            <!--<item name="adjustments" xsi:type="array"></item>-->
        </argument>
    </arguments>
</block>

This is the line that is changed in the above file.

<item name="render_template" xsi:type="string">Custom_BlancoLayout::product/price/final_price.phtml</item>

Now the price is rendering from the above file for the main product,
enter image description here

but the price design for the other sections on the product page also changed. Like for related products.

enter image description here

I want to show the price in this style only for main product and not for other sections.
I could not think of any solution. Please suggest how I can achieve this. I am really stuck.