1

I want to completely hide the price from the store. Be it in the catalog, product, minicart or cart. I need to do this through a custom module.

Any help is appreciated. Thanks!

1

This is a whole story here. But this should get you going.

The block used for product rendering in product view, product listing and so on is Magento\Catalog\Pricing\Render.

One example of usage in a layout file could be something like this.

<block class="Magento\Catalog\Pricing\Render" name="product.price.final">
     <arguments>
         <argument name="price_render" xsi:type="string">product.price.render.default</argument>
         <argument name="price_type_code" xsi:type="string">final_price</argument>
         <argument name="zone" xsi:type="string">item_view</argument>
    </arguments>
</block>

To remove a block you need to extend the layout file in your module|theme.

After extending the layout file you can remove a block with the following instruction

<referenceBlock name="block_name" remove="true"/>

What I would start doing is

  • create a custom module
  • identify every layout file where Magento\Catalog\Pricing\Render is used.
  • Decide if I want it removed from there and remove if so.

For the checkout area is a whole other story. Checkout is rendered with ui components. And some other areas that use them. I'm not sure how you are going to go about that.

This is the recently viewed widget where price is included via ui components. link to widget

| improve this answer | |
  • I need to hide price for a specific store and not all of them. If I try to use ifconfig with referenceBlock, I get an error that ifconfig is not allowed with referenceBlock. Is there a way to hide price from everywhere using php? – coderGeek Jul 4 '19 at 20:34
0

Completely hide price from the store

app\code\Vendorename\Modulename\etc\frontend

di.xml

<?xml version="1.0" encoding="UTF-8"?>

<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="price_hide" type="Vendorename\Modulename\Plugin\HidePriceBox" sortOrder="1" disabled="false"/>
    </type>
</config>

app\code\Vendorename\Modulename\Plugin

HidePriceBox.php

<?php

namespace Vendorename\Modulename\Plugin;

class HidePriceBox
{
    function afterToHtml(\Magento\Catalog\Pricing\Render\FinalPriceBox $subject, $result)
    {
        // put your code for specific store view show and hide.
        // for show price box then use this line return $result;
        return ''; // hide price
    }
}

I Hope This Helps You.

| improve this answer | |

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.