从YITH发票插件中的订单获取Woocommerce货币符号

时间:2017-10-06 13:31:17

标签: php wordpress woocommerce currency orders

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

我已尝试更改各种可用的货币切换器插件,但该符号在发票中不会更改,只需使用默认的货币符号。

我甚至尝试添加' get_woocommerce_currency_symbol()'货币arg数组到YITH函数。我需要帮助。使用的插件是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 );
}

1 个答案:

答案 0 :(得分:3)

获取订单货币符号(或代码)的唯一方法是首先获取 WC_Order 对象,然后您可以从{{1对象或来自global $order; with:

$order_id

现在您可以使用 $order = wc_get_order( $order_id ); 方法 WC_Abstract_Order 来获取货币代码,最后您将获得货币符号:

get_currency()

这已经过测试,适用于WooCommerce 3 +

相关问题