{"id":107218,"date":"2017-12-30T15:49:11","date_gmt":"2017-12-30T15:49:11","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=107218"},"modified":"2023-07-26T12:34:00","modified_gmt":"2023-07-26T12:34:00","slug":"price-conversion-one-currency-another","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/","title":{"rendered":"Price conversion from one currency to another"},"content":{"rendered":"<p>Here is how you can convert the price from one currency to another.<\/p>\n<p>First of all, in the Constructor, create an instance of \u00a0&#8220;\\Magento\\Directory\\Model\\Currency&#8221; as below:<\/p>\n<pre class=\"brush:php\">public function __construct(\n    \\Magento\\Framework\\App\\Helper\\Context $context,\n     \\Magento\\Directory\\Model\\Currency $currency\n) {\n        parent::__construct($context);\n        $this-&gt;_currency = $currency;\n}\n<\/pre>\n<div>\n<p>then you can use the following function to get the updated price in the new currency.<\/p>\n<div>\n<pre class=\"brush:php\">public function getNewPrice($price, $currCodeFrom, $currCodeTo)\n{\n    $rate = $this-&gt;_currency-&gt;load($currCodeFrom)-&gt;getAnyRate($currCodeTo);\n    $newPrice = $price * $rate;\n    return newPrice;\n}<\/pre>\n<\/div>\n<p>here, <strong>$price<\/strong> is the amount that you want to convert, <strong>$currCodeFrom<\/strong> is the currency code from which the price has to be converted, and <strong>$currCodeTo<\/strong> is the currency Code in which you want the converted price.<\/p>\n<p>I have used this code in a helper, you can use this in Block or a Controller as per your need.<\/p>\n<p>For any queries, feel free to comment below. \ud83d\ude42<\/p>\n<p>Moreover, using <a href=\"https:\/\/store.webkul.com\/magento2-geoip-extension.html\" target=\"_blank\" rel=\"noopener\">Magento 2 GeoIP<\/a> module you can automatically change currency and select the store view based on the customer&#8217;s location.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here is how you can convert the price from one currency to another. First of all, in the Constructor, create an instance of \u00a0&#8220;\\Magento\\Directory\\Model\\Currency&#8221; as below: public function __construct( \\Magento\\Framework\\App\\Helper\\Context $context, \\Magento\\Directory\\Model\\Currency $currency ) { parent::__construct($context); $this-&gt;_currency = $currency; } then you can use the following function to get the updated price in the new <a href=\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":167,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[156,2460,5998],"class_list":["post-107218","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-currency","tag-magento-2","tag-price-conversion"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Price conversion from one currency to another - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Price conversion from one currency to another - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Here is how you can convert the price from one currency to another. First of all, in the Constructor, create an instance of \u00a0&#8220;MagentoDirectoryModelCurrency&#8221; as below: public function __construct( MagentoFrameworkAppHelperContext $context, MagentoDirectoryModelCurrency $currency ) { parent::__construct($context); $this-&gt;_currency = $currency; } then you can use the following function to get the updated price in the new [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-30T15:49:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-26T12:34:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Hemant Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hemant Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\"},\"author\":{\"name\":\"Hemant Jain\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/a824ac6c5c14d32569263100b85f47c6\"},\"headline\":\"Price conversion from one currency to another\",\"datePublished\":\"2017-12-30T15:49:11+00:00\",\"dateModified\":\"2023-07-26T12:34:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\"},\"wordCount\":137,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"currency\",\"Magento 2\",\"Price Conversion\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\",\"url\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\",\"name\":\"Price conversion from one currency to another - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2017-12-30T15:49:11+00:00\",\"dateModified\":\"2023-07-26T12:34:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Price conversion from one currency to another\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/a824ac6c5c14d32569263100b85f47c6\",\"name\":\"Hemant Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/184358b1c25c580a3e32952605156294dedfff2b8b75bdb2a719c8e6a5d318b6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/184358b1c25c580a3e32952605156294dedfff2b8b75bdb2a719c8e6a5d318b6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Hemant Jain\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/hemant-jain591\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Price conversion from one currency to another - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/","og_locale":"en_US","og_type":"article","og_title":"Price conversion from one currency to another - Webkul Blog","og_description":"Here is how you can convert the price from one currency to another. First of all, in the Constructor, create an instance of \u00a0&#8220;MagentoDirectoryModelCurrency&#8221; as below: public function __construct( MagentoFrameworkAppHelperContext $context, MagentoDirectoryModelCurrency $currency ) { parent::__construct($context); $this-&gt;_currency = $currency; } then you can use the following function to get the updated price in the new [...]","og_url":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-12-30T15:49:11+00:00","article_modified_time":"2023-07-26T12:34:00+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Hemant Jain","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Hemant Jain","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/"},"author":{"name":"Hemant Jain","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/a824ac6c5c14d32569263100b85f47c6"},"headline":"Price conversion from one currency to another","datePublished":"2017-12-30T15:49:11+00:00","dateModified":"2023-07-26T12:34:00+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/"},"wordCount":137,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["currency","Magento 2","Price Conversion"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/","url":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/","name":"Price conversion from one currency to another - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2017-12-30T15:49:11+00:00","dateModified":"2023-07-26T12:34:00+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/price-conversion-one-currency-another\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Price conversion from one currency to another"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/a824ac6c5c14d32569263100b85f47c6","name":"Hemant Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/184358b1c25c580a3e32952605156294dedfff2b8b75bdb2a719c8e6a5d318b6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/184358b1c25c580a3e32952605156294dedfff2b8b75bdb2a719c8e6a5d318b6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Hemant Jain"},"url":"https:\/\/webkul.com\/blog\/author\/hemant-jain591\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/167"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=107218"}],"version-history":[{"count":4,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107218\/revisions"}],"predecessor-version":[{"id":392820,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/107218\/revisions\/392820"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=107218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=107218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=107218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}