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
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]
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With