j8d
j8d

Reputation: 510

Show currencies with different numbers of decimal places

I have a Wordpress site that uses woocommerce and woocommerce currency switcher plugins. The site displays prices in Thai Baht in Thailand and USD everywhere else. I want the shopping cart to show Thai Baht with 0 decimal places and USD with 2 decimal places. If I set woocommerce to display 2 decimal places for all currencies, is there some function I could add that would strip the '.00' from every displayed instance of '.00฿'?

Here's what I have so far...

function strip_zeros($baht) {
foreach($baht as $i) {
$baht= strtr($baht, ".00฿", "฿");
}
return $baht;
}
add_filter('the_content','strip_zeros');

Upvotes: 0

Views: 538

Answers (2)

user4777196
user4777196

Reputation:

Try this,it works fine for me

function strip_zeros($baht) {
foreach($baht as $i) {
$baht= sprintf("%02d",$baht);
}
return $baht;
}
add_filter('the_content','strip_zeros');

Main point is sprintf("%02d",$baht);

Upvotes: 1

j8d
j8d

Reputation: 510

The simple solution was to add the following line of code to the plugin index.php file:

public $no_cents = array('THB');

Upvotes: 0

Related Questions