Going to use the Around plugin to change $0.00 to as “Free” text. You can follow below steps to get it done:
For PLP and PDP, you can replace your module name as per given exapmle
app/code/MM/Training/etc/frontend/di.xml
1 2 3 4 5 6 7 8 9 |
<?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\Framework\Pricing\Render\PriceBox"> <plugin name="change_text_for_free_product" type="MM\Training\Plugin\Pricing\Render\PriceBox" sortOrder="1"/> </type> </config> |
app/code/MM/Training/Plugin/Pricing/Render/PriceBox.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php namespace MM\Training\Plugin\Pricing\Render; use Magento\Framework\Pricing\Amount\AmountInterface; class PriceBox { public function aroundRenderAmount( \Magento\Framework\Pricing\Render\PriceBox $subject, \Closure $proceed, AmountInterface $amount, array $arguments = [] ) { if ($subject->getPrice()->getValue() <= 0) { return 'Free'; } return $proceed($amount, $arguments); } } |
Just flush your Magento cache and changes will reflect over the frontend. It will be displayed as “free” instead of “$0.00” amount in your store frontend.