从YITH发票插件中的订单中获取Woocommerce货币符号 [英] Get Woocommerce currency symbol from order in YITH invoice plugin

查看:97
本文介绍了从YITH发票插件中的订单中获取Woocommerce货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的WooCommerce网站有2种货币.主要货币为印度货币卢比,次要货币为 USD (使用货币切换器).我尝试以美元下订单,但YITH发票在发票上显示了主要的印度卢比符号.

Our WooCommerce site has 2 currencies. The primary currency is the Indian rupee and the secondary currency is USD (using currency switcher). I tried placing an order in USD but the YITH invoice shows the primary Indian rupee symbol in the invoice.

我已尝试更改为可用的各种货币切换器插件,但发票中的符号不​​会更改,只是采用默认的货币符号.

I have tried changing to all sorts of currency switcher plugins available but the symbol won't change in the invoice, it simply takes the default currency symbol.

我什至尝试将'get_woocommerce_currency_symbol()'添加到Yarg函数的货币arg数组中.我需要帮助.使用的插件为YITH Invoice版本:1.3.11.

I even tried adding 'get_woocommerce_currency_symbol()' to currency arg array to the YITH function. I Need help. The plugin used is YITH Invoice ver: 1.3.11.

function yith_get_formatted_price ( $price, $args = array () ) {
    extract ( apply_filters ( 'wc_price_args', wp_parse_args ( $args, array (
        'ex_tax_label'       => false,
        'currency'           => get_woocommerce_currency_symbol (),
        'decimal_separator'  => wc_get_price_decimal_separator (),
        'thousand_separator' => wc_get_price_thousand_separator (),
        'decimals'           => wc_get_price_decimals (),
        'price_format'       => get_woocommerce_price_format (),
    ) ) ) );

    $negative = $price < 0;
    $price    = apply_filters ( 'raw_woocommerce_price', floatval ( $negative ? $price * - 1 : $price ) );
    $price    = apply_filters ( 'formatted_woocommerce_price', number_format ( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator );

    if ( apply_filters ( 'woocommerce_price_trim_zeros', false ) && $decimals > 0 ) {
        $price = wc_trim_zeros ( $price );
    }

    $formatted_price = ( $negative ? '-' : '' ) . sprintf ( $price_format, get_woocommerce_currency_symbol ( $currency ), $price );
    $return          = $formatted_price;

    return apply_filters ( 'wc_price', $return, $price, $args );
}

推荐答案

获取订单货币符号的唯一方法(或代码)是首先获取 WC_Order code> 对象,您可以从 global $ order; 对象或 $ order_id 对象使用以下方式获取它:

The only way to get the order currency symbol (or code) is first getting the WC_Order object and you can get it from the global $order; object or from the $order_id with:

$order = wc_get_order( $order_id ); 

现在,您可以在其上使用 WC_Abstract_Order 方法 get_currency() 来获取货币代码,最后您将通过以下方式获得货币符号:

Now you can use on it the WC_Abstract_Order method get_currency() to get the currency code and finally you will get the currency symbol this way:

$currency_code = $order->get_currency();
$currency_symbol = get_woocommerce_currency_symbol( $currency_code );

这已经过测试,可以在WooCommerce 3+上使用

This is tested and works on WooCommerce 3+

这篇关于从YITH发票插件中的订单中获取Woocommerce货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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