【问题标题】:Show currencies with different numbers of decimal places显示具有不同小数位数的货币
【发布时间】:2015-09-29 08:18:36
【问题描述】:

我有一个使用 woocommerce 和 woocommerce 货币切换器插件的 Wordpress 网站。该网站以泰国泰铢和其他地方的美元显示价格。我希望购物车显示小数点后 0 位的泰铢和小数点后 2 位的美元。如果我将 woocommerce 设置为显示所有货币的小数点后 2 位,是否可以添加一些函数来从每个显示的“.00฿”实例中删除“.00”?

这是我目前所拥有的......

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

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    试试这个,对我来说很好用

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

    重点是sprintf("%02d",$baht);

    【讨论】:

      【解决方案2】:

      简单的解决方案是将以下代码行添加到插件 index.php 文件中:

      public $no_cents = array('THB');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-22
        • 2016-04-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-29
        相关资源
        最近更新 更多