【发布时间】:2020-12-10 00:06:23
【问题描述】:
我有以下代码,显示了 php 模板发票中自定义字段的值,其中我还显示了订单货币的代码,但货币符号没有出现,我使用的部分代码来自回答问题的@LoicTheAztec,显示订单货币的代码和符号Get Woocommerce currency symbol from order in YITH invoice plugin
<?php
$custom_order_meta = get_post_meta($order->get_order_number(), 'costoseguro', true);
if( ! empty($custom_order_meta) )
{ ?>
<p> <?php
printf( '<b>Insured Package Value:</b> ' . esc_html( '%s', 'woocommerce' ), esc_html($custom_order_meta) );?> <?php $currency_code = $order->get_currency();
$currency_symbol = get_woocommerce_currency_symbol( $currency_code ); ?></p> <?php
}
?>
在 fuctions.php 文件中,我使用此代码更改货币符号和代码:`
add_filter( 'woocommerce_currency_symbol', 'change_currency_symbol', 10, 2 );
function change_currency_symbol( $symbols, $currency ) {
if ( 'USD' === $currency ) {
return 'USD $ ';
}
if ( 'EUR' === $currency ) {
return 'EUR € ';
}
if ( 'COP' === $currency ) {
return 'COP $';
}
return $symbols;
}
`
【问题讨论】:
标签: php wordpress woocommerce