一個可能的解決方案是使用JavaScript來讀取無論是運送或帳單國家,然後顯示相關付款方法。
這裏有一個概念性的例子假設你知道如何選擇特定元素(使用瀏覽器的開發者工具,以確定正確的選擇爲你的目標元素)..
/**
* This example binds a change event to the shipping country input dropdown,
* so whenever a country is selected or changed, this code will show the relevant
* payment methods.
* NOTE: The change method here might not work if the payment methods section
* is inaccessible at the time of country selection, at which point you should
* modify the code to read the country at the time of DOM load for the payment methods.
*/
//** Whenever the shipping country is selected or changed **//
$("#shipping_country_dropdown").change(function() {
// Hide/Clear all visible payment options:
$(".payment_methods :input").each(function() {
$(this).hide();
});
togglePaymentMethodsByCountry($(this).find('option:selected').text());
});
/**
* Displays specific payment methods depending on the customer's selected billing or shipping country.
* You set the list of countries and their allowed payment methods here.
* @param country String - The customer selected country.
* @return Void
*/
function togglePaymentMethodsByCountry(country) {
//** Define your country/payment options here, countries in caps **//
switch(country.toUpperCase()) {
case "UNITED STATES OF AMERICA":
$('#payment_method_1').show();
$('#payment_method_2').show();
$('#payment_method_3').show();
break;
case "CANADA":
$('#payment_method_1').show();
$('#payment_method_2').show();
break;
default:
// For all other countries not listed above:
$('#payment_method_3').show();
break;
}
}