2017-10-06 74 views
1

我们WooCommerce站点有2种货币。主货币是印度卢比和次要货币是USD(使用货币切换器)。我试图订货在USD但YITH发票示出了在发票主印度卢比符号。获取Woocommerce货币符号从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

获取订单货币符号(或者代码),唯一的办法就是先得到WC_Order对象,并可以从global $order;对象或从$order_id用得到它:

$order = wc_get_order($order_id); 

现在你可以使用WC_Abstract_Order方法get_currency()到g等货币代码,最终你会得到货币符号是这样的:

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

这是测试和工程上WooCommerce 3+

+1

是的,这工作完美。由于$ current_order = $ document-> order;已在发票功能页面中定义。然后我必须添加一个方法// global $ woocommerce; $ order_currency = $ current_order-> get_order_currency();其次是地方wc_price来获得价格阵列(“货币” => $ order_currency)。 – SandeepTete