Posted on

Magento 2 – Hiding prices by customer

I am trying to hide prices when a specific customer attribute is set to “true”.
Because of FP-Caching, this has been very difficult to accomplish.

I can’t update the FinalPriceBox directly with plugin, as this data gets cached and switching the value on / off on customer entity doesn’t update on frontend with caching enabled. Attempting to disable cache for that block alone actually disables cache for the entire page which is no good.

I have also attempted to create my own component, that can hide or display the block and provide the customer attribute via plugin for MagentoCustomerCustomerDataCustomer => Magento_Customer/js/view/customer-data.
However this gives complications on first page loaded after login (data is not upto-date). Also this saves the field into the cookie storage, which would mean that variable can be controlled on client-side cookie.

Any suggestions of an approach to display the price when the customer attribute is “false” and display a custom block when customer attribute is “true”? Must maintain all cacheable blocks.

Maybe adding new section-data that will load specific to my module?

Leave a Reply

Your email address will not be published. Required fields are marked *