在woocommerce中添加货币代码以定价

时间:2017-02-24 02:28:56

标签: jquery wordpress woocommerce

我在国际woocommerce商店运行currency switching widget。我正在研究一些jquery,以便将国家代码添加到价格中。因此,价格不会显示为500美元,而是显示为500美元,并在用户更改货币时更新。

直到点击它才能正常工作。 console.log ( newcurrency );会在点击时记录正确的国家/地区代码,但下一行无效。

$(function() {

    // Get current currency
    var currency = $( ".currency_switcher .active" ).text();

    // Add currency before price
    $( ".woocommerce-Price-amount" ).prepend( currency );

    //On click, update currency
    $( ".currency_switcher li a" ).click(function() {

        var newcurrency = $(this).text();

        console.log ( newcurrency );
        $( ".woocommerce-Price-amount" ).prepend( newcurrency );

    });

});

有什么想法为什么这条线不起作用?

1 个答案:

答案 0 :(得分:0)

**解决方案1:**添加自定义货币/符号

要在WooCommerce 2.0+中添加自定义货币,请将此代码复制并粘贴到主题functions.php文件中,并将货币代码和符号换成您自己的货币。

保存更改后,应该可以从您的WooCommerce设置中获取更改。

add_filter( 'woocommerce_currencies', 'add_my_currency' );

function add_my_currency( $currencies ) {
     $currencies['ABC'] = __( 'Currency name', 'woocommerce' );
     return $currencies;
}

add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2);

function add_my_currency_symbol( $currency_symbol, $currency ) {
 case 'ABC': $currency_symbol = '$'; break; {
}
 return $currency_symbol;
}

如果使用子主题,代码不会受到更新的影响。

**解决方案2:** View this link **解决方案3:** View this link

相关问题