To remove a custom field from the checkout in WooCommerce when a specific product is in the shopping cart, you can use the function woocommerce_checkout_fields
and remove the field based on the product. Here's some sample code that might help you:
add_filter( 'woocommerce_checkout_fields', 'remove_custom_field_based_on_product' ); function remove_custom_field_based_on_product( $fields ) { // Hier die Produkt-ID einfügen, die das benutzerdefinierte Feld ausblenden soll $product_id = 123; // Überprüfen, ob das Produkt im Warenkorb ist foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { if ( $cart_item['product_id'] == $product_id ) { // Wenn das Produkt im Warenkorb ist, entfernen Sie das benutzerdefinierte Feld unset( $fields['billing']['billing_custom_field'] ); break; } } return $fields; }
In this example, the custom field named billing_custom_field
removed from the checkout if the product with the ID 123
in the shopping cart. You can customize the code to remove the custom field you want to hide and the product that triggers the action.