I have created events observer which is working fine to check whether the customer is logged in or not. If the customer is not logged in then the price will not be displayed.

Here's my code:

custom_log_out.xml in


<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="render.product.prices">
            <argument name="default" xsi:type="array">
                <item name="prices" xsi:type="array">
                    <item name="final_price" xsi:type="array">
                        <item name="render_template" xsi:type="string">Demo_Mymodule::product/price/final_price.phtml</item>

Then created final_price.phtml in


which have my custom code:

<p>Login to Continue</p>

But it's not working can please anyone guide me?


The best approach is to create plugin and use "around" on toHtml function in this class Magento\Catalog\Pricing\Render\FinalPriceBox

Create di.xml file in your module

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Catalog\Pricing\Render\FinalPriceBox">
        <plugin name="cataloghideprice_finalpricebox" type="{vendor}\{module}\Plugin\FinalPriceBox"/>


Create this file {vendor}{module}\Plugin\FinalPriceBox.php


namespace {vendor}\{module}\Plugin;

class FinalPriceBox
    function aroundToHtml($subject, callable $proceed)
            return '';
            return $proceed();



Don't forget to replace {vendor} and {module} with your names.

after that execute those commands

php bin/magento setup:upgrade

php bin/magento setup:di:compile

  • Thanks for the response. Well, actually I am looking to do that using event observer. – Syed Muneeb Ul Hasan Jul 20 '18 at 13:41
  • Yes that may work, I tried the event observer but i had some issues, plugin help me a lot – WISAM HAKIM Jul 20 '18 at 13:43

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.