WooCommerce货币符号 [英] WooCommerce Currency Symbol

查看:124
本文介绍了WooCommerce货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近正在为我的客户使用WooCommerce WordPress项目,并且正在编辑WooCommerce WordPress的插件.我正在尝试使用此功能显示包含货币代码的产品价格

I am recently working with WooCommerce WordPress project for my client and I am editing a plugin for WooCommerce WordPress. I am trying to display the product price to include the currency code use this function

 * @param mixed $item
 * @param bool $inc_tax (default: false).
 * @param bool $round (default: true).
 * @return float
 */
public function get_item_total( $item, $inc_tax = false, $round = true ) {

    $qty = ( ! empty( $item['qty'] ) ) ? $item['qty'] : 1;

    if ( $inc_tax ) {
        $price = ( $item['line_total'] + $item['line_tax'] ) / max( 1, $qty );
    } else {
        $price = $item['line_total'] / max( 1, $qty );
    }

    $price = '<span class="price">' . $round ? round( $price, wc_get_price_decimals() ) . '</span>' : '<span class="price">' . $price . '</span>' ;

    return apply_filters( 'woocommerce_order_amount_item_total',  $price, $this, $item, $inc_tax, $round ); 
}

但是它会吐出一个像55这样的数字,并且没有货币符号.反正有没有用货币符号表示的数字,例如$ 55?

But it spits out a number like 55 with out the currency symbol. is there anyway get the number with currency symbol like $55 ?

感谢您的帮助

推荐答案

ty rgdesign

ty rgdesign

这是现在可以解决的问题

This was the fix it works now

public function get_item_total( $item, $inc_tax = false, $round = true ) {

    $qty = ( ! empty( $item['qty'] ) ) ? $item['qty'] : 1;

    if ( $inc_tax ) {
        $price = ( $item['line_total'] + $item['line_tax'] ) / max( 1, $qty );
    } else {
        $price = $item['line_total'] / max( 1, $qty );
    }

   $currency_symbol = get_woocommerce_currency_symbol();

   $price = $round ? round($price, wc_get_price_decimals() ): $price;

$price = '<span class="price">' .$currency_symbol . $price .'</span>';  
    return apply_filters( 'woocommerce_order_amount_item_total',$price, $this, $item, $inc_tax, $round ); 
}

这篇关于WooCommerce货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆