在 Woocommerce 中,我使用以下代码显示仅针对特定城市的货到付款付款方式:
function payment_gateway_disable_city( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_shipping_city() == 'New York') {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_city' );
它工作正常。现在我需要处理多个城市,如华盛顿、旧金山等......
所以我尝试了以下方法:
function payment_gateway_disable_city( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_shipping_city() == 'New York', 'San Fransisco' ) {
unset( $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_city' );
但它不起作用……我收到“WordPress 遇到技术问题”的提示。
哆啦的时光机