Untitled
add_filter( 'woocommerce_available_payment_gateways', 'conditionally_disable_payment_gateways' ); function conditionally_disable_payment_gateways( $available_gateways ) { if (is_admin()){ return $available_gateways; } // Check if there are subscription products in the cart $has_subscription = false; foreach ( WC()->cart->get_cart() as $cart_item ) { if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $cart_item['data'] ) ) { $has_subscription = true; break; } } $is_vendor = marketking()->is_vendor( get_current_user_id() ); if ( $has_subscription && $is_vendor ) { if ( isset( $available_gateways['marketking_stripe_gateway'] ) ) { unset( $available_gateways['marketking_stripe_gateway'] ); } } else { if ( isset( $available_gateways['stripe'] ) ) { unset( $available_gateways['stripe'] ); } } return $available_gateways; }
Leave a Comment