我的代码用于为客人和客户隐藏 BACS 支付网关,但我需要更改它,以便 BACS 网关只有在客户/管理员在 CART 或 CHECKOUT 上应用名为 FOOD 的特定优惠券代码时才可用。
换句话说:隐藏 BACS 网关,直到名为 FOOD 的 COUPON 应用于 CART 或 CHECKOUT。
这是我的代码:
add_filter('woocommerce_available_payment_gateways', 'show_bacs_if_coupon_is_used', 99, 1);
function show_bacs_if_coupon_is_used( $available_gateways ) {
$current_user = wp_get_current_user();
if ( isset($available_gateways['bacs']) && (current_user_can('customer'))) {
unset($available_gateways['bacs']);
} else if ( isset($available_gateways['bacs']) && !is_user_logged_in()) {
unset($available_gateways['bacs']);
}
return $available_gateways;
}