如何在WooCommerce中显示包含货币详细信息的金额拼写

如何在WooCommerce中显示包含货币详细信息的金额拼写,woocommerce,hook-woocommerce,Woocommerce,Hook Woocommerce,我试图在我的invoice.phptemplate文件中拼出WooCommerce订单总额 首先,我尝试: $total = $order->get_total(); <?php echo ( $total ); ?> - <?php $f = new NumberFormatter("en", NumberFormatter::SPELLOUT); echo $f->format($total); ?> $total=$ord

我试图在我的
invoice.php
template文件中拼出WooCommerce订单总额

首先,我尝试:

$total = $order->get_total();
<?php echo ( $total ); ?> - 

<?php 
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format($total); ?>  
$total=$order->get_total();
- 
显示的订单总数为225.00,拼写显示为:225


编辑:

我找到了以下解决方案:

<?php  $number = $order->get_total() ;

$formatter = new NumberFormatter('tr', NumberFormatter::SPELLOUT);

$formatter->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%financial");

echo $formatter->format($number); ?>

但是结果显示:225

所需显示应为:225土耳其里拉,零便士


我该怎么做?

常量不处理小数

您可以使用以下自定义函数显示浮点数金额,如(带有货币详细信息):

代码进入活动子主题(或活动主题)的functions.php文件

用法:然后您将在代码中使用它,如下所示:

echo wc_spellout_amount( $order->get_total() );

经过测试,工作正常。

工作正常。非常感谢。如何获取大写字母的结果?@MusaBaltacı我刚刚更新了函数…要获取大写字母的结果,请使用
echo strtoupper(wc_spellout_amount($order->get_total())奇妙。非常感谢。
echo wc_spellout_amount( $order->get_total() );