TransWikia.com

How to change product price to custom text Magento 2

Magento Asked on January 2, 2022

I am planning to change product price from
Category view and product page to “coming soon” I have a new product attribute which I have created and I can see that when I edit product page from admin area.
If I enable that attribute the price is meant to change from the amount to “coming soon”

This is my Di.xml file

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Product page -->
    <type name="MagentoCatalogModelProduct">
        <plugin name="change_product" type="[vendor][module]PluginModelProduct"/>
    </type>

    <!-- Price changed in category level -->
    <type name="MagentoCatalogBlockProductListProduct">
        <plugin name="cataloghideprice_finalpricebox" type="[vendor][module]BlockProductListProduct" />
    </type>

</config>

The category level works perfectly
I can see coming soon, but the issue I am having is product page isn’t changing

Please can someone direct me to the right path.

One Answer

  1. You need to create catalog_product_prices.xml into your extension on following path : vendorExtensionviewbaselayoutcatalog_product_prices.xml

  2. Now copy the orginal file content catalog_product_prices.xml from following location : vendormagentomodule-catalogviewbaselayoutcatalog_product_prices.xml

  3. Now replace following line

    <item name="default_amount_render_template" xsi:type="string">Magento_Catalog::product/price/amount/default.phtml</item>
    

    with this :

    <item name="default_amount_render_template" xsi:type="string">Vendor_Extension::product/price/amount/default.phtml</item>
    
  4. Now copy the template file from

    Magento_Catalog::product/price/amount/default.phtml
    

    to

    Vendor_Extension::product/price/amount/default.phtml
    
  5. Now apply your logic into this file :

    Vendor_Extension::product/price/amount/default.phtml 
    

Answered by Dhiren Vasoya on January 2, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP