如何根据邮政编码隐藏 Woocommerce 中的付款方式 [英] How to Hide Payment Method in Woocommerce based on Postal Code
本文介绍了如何根据邮政编码隐藏 Woocommerce 中的付款方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这个 woocommerce 设置中,我有 2 种付款方式,Paypal 和货到付款.
In this woocommerce setup, I have 2 Payment methods, Paypal and Cash on Delivery.
现在如何仅针对某些邮政编码隐藏/禁用货到付款.
Now how can Cash on Delivery be hidden/disabled for certain Postal codes only.
这是我在 Gist 上找到的代码
This is the code I found on Gist
// Disable gateway based on country
function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['ccavenue'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
unset( $available_gateways['ccavenue'] );
} else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_country() == 'IN' ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
推荐答案
要禁用/隐藏货到付款",请将此代码放在您主题的 function.php 中.
To disable/hidden "Cash on Delivery", Place this code in your theme's function.php .
更多详情:woocommerce-hide-payment-gatway-based-on-访客国家
// Disable gateway based on country
function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
这篇关于如何根据邮政编码隐藏 Woocommerce 中的付款方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文