在woocommerce中添加货币代码到价格
问题描述:
我在我的国际woocommerce商店上运行currency switching widget。我正在一些jQuery的工作,以国家代码的价格。因此,而不是价格显示为500美元,它将显示为500美元,并更新时,用户更改货币。在woocommerce中添加货币代码到价格
它工作正常,直到点击。 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:**添加自定义货币/符号
要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
我的猜测是,它是通过AJAX添加或不存在。你应该检查生成的html(一个在Firefox中使用开发工具的选项)。使用像http://stackoverflow.com/a/29279081/1004312 – Christina