Question

How to display price currency symbol after the amount on the right side. from: USD333 to: 333USD

Was it helpful?

Solution

You can do it by writing single event observer

Create registration file:

Vendor\Module\registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Vendor_Module',
    __DIR__
);

Create module file:

Vendor\Module\etc\module.xml

<?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="Vendor_Module" setup_version="1.0.0"></module>        
</config>

Create event File:

app/code/Vendor/Module/etc/events.xml

<?xml version="1.0"?>    
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="currency_display_options_forming">
        <observer name="change_currency_position" instance="Vendor\Module\Model\Observer\ChangeCurrencyPosition" />
    </event>
</config>

Create observer File:

Write a observer file in app/code/Vendor/Module/Model/Observer with the file name ChangeCurrencyPosition.php

<?php        
namespace Vendor\Module\Model\Observer;    
use Magento\Framework\Event\ObserverInterface;    
class ChangeCurrencyPosition implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {    
        $currencyOptions = $observer->getEvent()->getCurrencyOptions();    
        $currencyOptions->setData('position', \Magento\Framework\Currency::RIGHT);  
        return $this;
    }    
}

Run Command:

php bin/magento setup:upgrade

OTHER TIPS

works in 2.4.2

-- app/code/Vendor/Module |-- etc | |-- events.xml | -- module.xml |-- Model | -- Observer | -- ChangeCurrencyPosition.php `-- registration.php

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top