0

I have created one module and it has system configuration on the admin side, where the admin has the functionality to enable/disable the module. As per system configuration, I need to hide the price from every place on the front end.

i.e. "catalog, category, wish-list, a related product, up-sell products, cart, checkout, orders, email, account dashboard, etc.."

from everywhere I need to hide the price if the module is enabled.

Is there any global file for the price which can be overridden and add the code for hiding price?

I found one file, But if we override \Magento\Catalog\Pricing\Render\FinalPriceBox and change in wrapResult() function, it works but it will affect only product page and home page not for wish-list and other places.

how can I achieve this functionality? Is anyone have any idea about it?

2 Answers 2

1

You will want to create an after plugin on this interface method definition: \Magento\Framework\Pricing\Render\PriceBoxRenderInterface::renderAmount.

You can achieve this by declaring this plugin in a app/etc/Vendor/ModuleName/etc/frontend/di.xml file like it's described here: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html#declaring-a-plugin

your plugin should look something like that:

<?php
namespace Vendor\ModuleName\Plugin;

class PriceBoxRenderDisabler {
    public function afterRenderAmount(
         \Magento\Framework\Pricing\Render\PriceBoxRenderInterface $subject,
         $result
    ) {
        //instead of assigning true fetch a value from the config
        $disabled = true;
        if($disabled) {
            return '';
        }

        return $result;
    }
}

After that make sure to run:

bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento cache:flush
1
  • its not woking please share the exact code and folder structure since i'm new to magento.
    – Ramesh R
    Commented Nov 26, 2019 at 14:18
0

Below code hide price from all location whether it is listing page, single product page , compare or wishlist etc.

File path: app/code/Solwin/Module1/view/base/layout/catalog_product_prices.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <block class="Magento\Framework\Pricing\Render\RendererPool" name="render.product.prices">
        <arguments>
            <argument name="default" xsi:type="array">
                <item name="default_render_class" xsi:type="string">Magento\Catalog\Pricing\Render\PriceBox</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">Magento\Framework\Pricing\Render\Amount</item>
                <item name="default_amount_render_template" xsi:type="string">Solwin_Module1::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">Magento\Catalog\Pricing\Render\FinalPriceBox</item>
                        <item name="render_template" xsi:type="string">Magento_Catalog::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">Magento\Catalog\Pricing\Render\ConfiguredPriceBox</item>
                        <item name="render_template" xsi:type="string">Magento_Catalog::product/price/configured_price.phtml</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </block>
</layout>

File Path: app/code/Solwin/Module1/view/base/templates/catalog/product/price/amount/default.phtml

Add below code in it or make it as blank:

<?php echo ""; ?>

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.