我向4个国家销售产品;美国,加拿大,英国和法国。我启用了2种结账方式;货到付款(cod)和Paypal。我想将鳕鱼限制在加拿大,并躲避其他国家。我尝试了下面的代码,但它使鳕鱼从所有国家(包括加拿大)消失。我知道我在这里做错了,我不是专家,所以需要你的帮助。感谢
/**
* @snippet WooCommerce Disable Payment Gateway for a Specific Country
*/
function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'France' ) {
unset( $available_gateways['cod'] );
} else if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == 'France' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
答案 0 :(得分:0)
这应该这样做。
function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'Canada' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );