In this example, you'll need to customize the hide_payment_method_for_specific_products function by changing the product IDs and the names of the payment methods you want to hide according to your needs. Add this function to your theme's functions.php, and it will hide the selected payment methods based on the product IDs.
Please note that this is just an example, and you'll need to adapt it to your specific needs and WooCommerce setup. Be sure to create a backup of your functions.php file before implementation to ensure you don't make any unwanted changes.
function hide_payment_method_for_specific_products($available_payment_methods) { // Überprüfe, ob das aktuelle WooCommerce-Produkt in deiner Bedingung ist if (is_checkout() && !empty(WC()->cart)) { $cart = WC()->cart; $hide_for_products = array(123, 456); // Hier die Produkt-IDs angeben, für die du die Bezahlmethode ausblenden möchtest // Überprüfe, ob sich eines der Produkte in der Warenkorbliste befindet foreach ($cart->get_cart() as $cart_item_key => $cart_item) { $product_id = $cart_item['product_id']; if (in_array($product_id, $hide_for_products)) { // Hier die Bezahlmethode(n) angeben, die du ausblenden möchtest $methods_to_hide = array('payment_method_to_hide1', 'payment_method_to_hide2'); // Entferne die auszublendenden Bezahlmethoden foreach ($methods_to_hide as $method) { if (isset($available_payment_methods[$method])) { unset($available_payment_methods[$method]); } } break; // Breche die Schleife ab, sobald ein passendes Produkt gefunden wurde } } } return $available_payment_methods; } add_filter('woocommerce_available_payment_gateways', 'hide_payment_method_for_specific_products');