How to display price in all currencies on OpenCart Product Page?

Objectives of the blog

After reading this blog we will be able to display price in all currencies in the product page of OpenCart 3.x

Problem Statement

By default, OpenCart 3.x display price of the product into the currency set as default or chosen by the end user. And to display the price in all available currencies there will be few changes in the default or core files of OpenCart. (In case you do not want to change the core files then it can be done either through VqMod or OcMod.)

Requirement

We would need to modify the below-mentioned files to show the price of the product in all available currencies in the product page.

Procedure to solve the issue-

Follow the below-mentioned steps –

Open product.php from Catalog/Controller/Product and search for

$results =

$this->model_catalog_product->getProductImages($this->request->get['product_id

']);

2. And, add the following statement after that –

$currencies = $this->model_localisation_currency->getCurrencies();

3. Again find following code snippet in the same file –

if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {

   $data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);

} else {

   $data['price'] = false;

}

4. And replace it with –

$data['price'] = array(); 
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {

   foreach ($currencies as $currency) {

       if ($currency['status']) {

           $data['price'][] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $currency['code']);

       }

    }

}

5. Open product.twig from catalog/view/theme/default/template/product and search for

<h2>{{ price }}</h2>

5. And replace it with –

{% for currency_price in price %} <h2>{{ currency_price }}</h2> {% endfor %}

Then, clear all Caches (ocmod cache, twig cache, vqmod cache)

That’s all.

Refer the screenshot below after applying changes into the code –

product-prices-in-all-currencies

Summary

After following the above procedure, you will be able to display the price in all available currencies in Product Page.

Leave a Reply

Your email address will not be published. Required fields are marked *