Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the price value without currency symbol?

I want to get price value without currency symbol in Product Page for OpenCart. I have use following code for that. but, it is not work perfectly.

I have found and used following code. in .tpl file.

<?php
 $pricenocurrency = $price;
 $pricenocurrency  = preg_replace( '/\D/', '', $pricenocurrency  );
 echo $pricenocurrency ;
?>

So, I get following result. but, I want to not remove dot(.) from price.

Default Price = 86.02€

I Got = 8602

I want to = 86.02

like image 584
HDP Avatar asked Jan 28 '26 20:01

HDP


2 Answers

add point to preg_replace condition

 $pricenocurrency  = preg_replace( '/[^.\d]/', '', $pricenocurrency  );

if text around price could contain digit, make it a little complicated to save only points after digit

(?<!\d)\.|[^\d]
like image 143
splash58 Avatar answered Jan 30 '26 09:01

splash58


The above solution works fine, but what if there are multiple currencies on your store.I would recommend to use default opencart functionality. Just do this,

In your controller do the following.

$data['price_without_symbol'] = $this->currency->format($amount,$currency_code,$currency_value,false);

Will result in price without currency symbol. And use it in your .tpl file. Recommended if your store supports multi-currency. Rest for knowledge. :)

like image 25
Vidhyut Pandya Avatar answered Jan 30 '26 11:01

Vidhyut Pandya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!