Step 1: First you need to add di.xml in the following path:
app/code/Magemonkey/PriceAdjustment/etc/frontend
Now add the below code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoTaxObserverUpdateProductOptionsObserver" type="MagemonkeyPriceAdjustmentObserverUpdateProductOptionsObserver" />
</config>
Step 2: Next, you need to add module.xml file in the following path:
app/code/Magemonkey/PriceAdjustment/etc
Add the below code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Magemonkey_PriceAdjustment" setup_version="1.0.0">
<sequence>
<module name="Magento_Tax"/>
</sequence>
</module>
</config>
Step 3: Now you need to add registration.php file in the following path:
app/code/Magemonkey/PriceAdjustment
Add the below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Magemonkey_PriceAdjustment',
__DIR__
);
Step 4: Lastly, you need to add the UpdateProductOptionsObserver.php file in the following path:
app/code/Magemonkey/PriceAdjustment/Observer
And add the below code:
<?php
namespace MagemonkeyPriceAdjustmentObserver;
use MagentoFrameworkEventObserverInterface;
class UpdateProductOptionsObserver extends MagentoTaxObserverUpdateProductOptionsObserver
{
/**
* Tax data
*
* @var MagentoTaxHelperData
*/
protected $taxData;
/**
* @var MagentoFrameworkRegistry
*/
protected $registry;
/**
* @param MagentoTaxHelperData $taxData
* @param MagentoFrameworkRegistry $registry
*/
public function __construct(
MagentoTaxHelperData $taxData,
MagentoFrameworkRegistry $registry
) {
$this->taxData = $taxData;
$this->registry = $registry;
}
/**
* Change default JavaScript templates for options rendering
*
* @param MagentoFrameworkEventObserver $observer
* @return $this
*/
public function execute(MagentoFrameworkEventObserver $observer)
{
$response = $observer->getEvent()->getResponseObject();
$options = $response->getAdditionalOptions();
$_product = $this->registry->registry('current_product');
if (!$_product) {
return $this;
}
$algorithm = $this->taxData->getCalculationAlgorithm();
$options['calculationAlgorithm'] = $algorithm;
// prepare correct template for options render
if ($this->taxData->displayBothPrices()) {
$options['optionTemplate'] = sprintf(
'<%%= data.label %%>'
. '<%% if (data.finalPrice.value) { %%>'
. ' +<%%= data.basePrice.formatted %%> (%1$s <%%= data.finalPrice.formatted %%>)'
. '<%% } %%>',
__('Incl. tax:')
);
} elseif ($this->taxData->priceIncludesTax() && $this->taxData->displayPriceExcludingTax()) {
$options['optionTemplate'] = sprintf(
'<%%= data.label %%>'
. '<%% if (data.basePrice.value) { %%>'
. ' +<%%= data.basePrice.formatted %%>'
. '<%% } %%>'
);
}
$response->setAdditionalOptions($options);
return $this;
}
}

