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?

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
  • its not woking please share the exact code and folder structure since i'm new to magento. – Ramesh R Nov 26 '19 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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