How to remove checkout fields from specific products in checkout page

add_filter( 'woocommerce_checkout_fields' , 'hide_checkout_fields' );

function hide_checkout_fields( $fields ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$id = $product->get_id();
$products = array(2516, 584, 2454); // Product Ids

if (in_array($id, $products)) 
{ 
unset($fields['order']['how_heard']);
unset($fields['order']['member_level']);
}

}
return $fields; 
}

Leave a Reply

Your email address will not be published. Required fields are marked *