我有一个功能,改变货币取决于选择的国家。它只是重定向到相同的页面,但具有不同的currency
值。
脚本:
$("select#billing_country").change(function(){
if($(this).val()=="UA")
{
$("li.wc_payment_method.payment_method_cod").show();
$("p#billing_last_name_field").show();
$("p#billing_street_field").hide();
$("p#billing__house_field").hide();
$("p#billing_appartement_field").hide();
$("select#billing_country").val("UA");
$(location).attr('href', 'https://www.fashiondance.in.ua/checkout/?currency=UAH');
}
if($(this).val()=="RU")
{
$("li.wc_payment_method.payment_method_cod").hide();
$("p#billing_last_name_field").hide();
$('input:radio[name=payment_method][value=interkassa]').click();
$("p#billing_street_field").show();
$("p#billing__house_field").show();
$("p#billing_appartement_field").show();
$("select#billing_country").val("RU");
$(location).attr('href', 'https://www.fashiondance.in.ua/checkout/?currency=RUB');
}
else{
$("li.wc_payment_method.payment_method_cod").hide();
$("p#billing_last_name_field").hide();
$('input:radio[name=payment_method][value=interkassa]').click();
$("p#billing_street_field").show();
$("p#billing__house_field").show();
$("p#billing_appartement_field").show();
$(location).attr('href', 'https://www.fashiondance.in.ua/checkout/?currency=USD');
}
});
我想做的第一重定向页面比我想给选择一个国家它有的值。如果选择了俄罗斯而我选择了乌克兰,货币为uah
但选择将停留ru
。我怎么能这样做
试试这个
const currencies = {
"UA": "UAH",
"RU": "RUB",
"US": "USD"
}
const $billingCountry = $("#billing_country");
const toggle = function() {
const cur = $billingCountry.val();
$("li.wc_payment_method.payment_method_cod").toggle(cur === "UA");
$("p#billing_last_name_field").toggle(cur === "UA");
$("p#billing_street_field").toggle(cur !== "UA");
$("p#billing__house_field").toggle(cur !== "UA");
$("p#billing_appartement_field").toggle(cur !== "UA");
$("select#billing_country").val(cur);
localStorage.setItem("savedCur", cur);
$(location).attr('href', 'https://www.fashiondance.in.ua/checkout/?currency=' + currencies[cur]);
}
$billingCountry.on("change", toggle)
let savedCur = localStorage.getItem("savedCur"); // you can do this on the checkout page too
if (savedCur) {
$billingCountry.val(savedCur);
$billingCountry.change()
}