This weeks layout how-to for Magento 2 covers removing the price via a layout update from a product page. Useful for those edge cases and scenarios where a price is not needed on a page. Who knows!! I write these how to docs because we get asked for all sorts of things and they are obviously hard to find so we’re on a mission to make them easier!!
Magento 2 XML Layout Updates – In brief
A layout update is a small bit of code written in XML format that instructs the Magento CMS to look in a particular section of the page and either pick up or put down another piece of code. In each of the how-to sections below I’ll write out what each of the Magento Layout Updates are doing in a human way so they are more easy to understand.
So let’s get going
For all examples in this guide of XML updates you will need to:
- replace block_namespace_here with a custom name for your block such as custom.product.message. This can be anything really that follow this format but try and keep them the same across your site when they are doing the same thing.
- replace block_identifier_here with the block identifier (the ID of the static block)
Where to add the code
Whether you are doing a Magento XML Layout update on a category, product or CMS page you’ll be looking for a box that looks like this one to make your edits. You can do layout updates on pages, products and categories.
How to remove the price from a product page in Magento 2
Maybe you want customers to call you and you are going to tie this layout update in with a custom message. Maybe the item is out of stock and you don’t know what the price will be when it comes back in. Whatever reason you may have you’ll probably want to hide the price in a Magento store without ringing the developers.
- Use this code in the design xml layout update field on the product to remove the price. You can do it on a product by product basis you could use the bulk update attributes feature.
<referenceBlock name="product.price.final" remove="true"/>
The result of using this code to remove the price can be seen here on our Lumarix Magento Store
Why remove the price from a product page in Magento 2
- Couple with a message for “Call for price”
- Maybe you are displaying the price somewhere else and don’t need it twice.
- You want people to shop without knowing the price. You know what they say…if you have to ask!
Would you like to learn more? Would you rather we just did these things for you?
Call us on 0117 2077504 or complete the form below to discuss your project or requirements.