3

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

2

3 Answers 3

2

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]
2

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. :)

-1

You can use this also

<?php
    $pricenocurrency = $price;
    $pricenocurrency  = preg_replace( '/[^0-9.]/', '', $pricenocurrency  );
    echo $pricenocurrency ;
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.