根据所选货币隐藏 Woocommerce 中的付款方式
Hide payment methods in Woocommerce, according to selected currency
在结帐页面上,我们有美元、欧元、印度卢比、英镑货币的货币切换器。
但是,在 3 个网关中,只有 1 个网关支持所有货币,2 个支持 INR。
所以,如果有人选择美元、欧元和英镑,我需要隐藏其他两个网关
我们可以使用 selected currency
并完成所需的功能吗?
TIA
如果购物车中有特定产品,我会使用它来删除网关:
add_filter('woocommerce_available_payment_gateways','filter_gateways',1);
function filter_gateways($gateways){
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values ) {
$product_ = array(1063);
if(in_array($values['product_id'],$product_)){
unset($gateways['paypal']);
break;
}}
return $gateways;
}
我不知道你的货币切换器是从什么获取任何变量来修改 woocommerce_available_payment_gateways 过滤器的。
好的。找到了解决办法。如果有人在这里绊倒,请在下面提供详细信息。
"WooCommerce Currency Switcher" 插件更改 shop currency
& 使用会话/瞬态方法存储。不仅如此,它还 为每种选定的货币添加一个正文 class。
例如: currency-usd
或 currency-eur
或 currency-gbp
只需使用 CSS
就可以做到这一点
.currency-usd .payment_method_instamojo, .currency-usd .payment_method_paynimo, .currency-eur .payment_method_instamojo, .currency-eur .payment_method_paynimo, .currency-gbp .payment_method_instamojo, .currency-gbp .payment_method_paynimo {display:none}
这按预期工作w/o 编写一个单独的函数。希望这有帮助。
这是工作代码,我已经在 [www.edupediapublications.org][1]
上实现了它
add_filter('woocommerce_available_payment_gateways', 'woocs_filter_gateways', 1);
function woocs_filter_gateways($gateway_list)
{
global $WOOCS;
$exclude = array(
'paypal' => array('EUR', 'GBP'), //do not show paypal gate if current currency is EUR or GBP
'stripe' => array('USD')//do not show stripe gate if current currency is USD
);
//***
foreach ($exclude as $gateway_key => $currencies)
{
if (isset($gateway_list[$gateway_key]) AND in_array($WOOCS->current_currency, $currencies))
{
unset($gateway_list[$gateway_key]);
}
}
return $gateway_list;
}
在结帐页面上,我们有美元、欧元、印度卢比、英镑货币的货币切换器。
但是,在 3 个网关中,只有 1 个网关支持所有货币,2 个支持 INR。
所以,如果有人选择美元、欧元和英镑,我需要隐藏其他两个网关
我们可以使用 selected currency
并完成所需的功能吗?
TIA
如果购物车中有特定产品,我会使用它来删除网关:
add_filter('woocommerce_available_payment_gateways','filter_gateways',1);
function filter_gateways($gateways){
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values ) {
$product_ = array(1063);
if(in_array($values['product_id'],$product_)){
unset($gateways['paypal']);
break;
}}
return $gateways;
}
我不知道你的货币切换器是从什么获取任何变量来修改 woocommerce_available_payment_gateways 过滤器的。
好的。找到了解决办法。如果有人在这里绊倒,请在下面提供详细信息。
"WooCommerce Currency Switcher" 插件更改 shop currency
& 使用会话/瞬态方法存储。不仅如此,它还 为每种选定的货币添加一个正文 class。
例如: currency-usd
或 currency-eur
或 currency-gbp
只需使用 CSS
就可以做到这一点.currency-usd .payment_method_instamojo, .currency-usd .payment_method_paynimo, .currency-eur .payment_method_instamojo, .currency-eur .payment_method_paynimo, .currency-gbp .payment_method_instamojo, .currency-gbp .payment_method_paynimo {display:none}
这按预期工作w/o 编写一个单独的函数。希望这有帮助。
这是工作代码,我已经在 [www.edupediapublications.org][1]
上实现了它add_filter('woocommerce_available_payment_gateways', 'woocs_filter_gateways', 1);
function woocs_filter_gateways($gateway_list)
{
global $WOOCS;
$exclude = array(
'paypal' => array('EUR', 'GBP'), //do not show paypal gate if current currency is EUR or GBP
'stripe' => array('USD')//do not show stripe gate if current currency is USD
);
//***
foreach ($exclude as $gateway_key => $currencies)
{
if (isset($gateway_list[$gateway_key]) AND in_array($WOOCS->current_currency, $currencies))
{
unset($gateway_list[$gateway_key]);
}
}
return $gateway_list;
}