'Unset billing_company if specific value is true

Im trying to create a WooCommerce function, where I unset the billing_company checkout field, if my custom checkout field billing_private_company has the value 1. 1 is for a private customer, 2 is for a company customer.

The customer comes from a form, where it fills all fields and then enters checkout. On entering checkout, I need this function to unset the field billing_company, if its a private customer.

At the moment, its unsetting the field, regardless if the billing_private_company field hast 1 or 2 as value.

Here is what I have so far:

add_filter( 'woocommerce_checkout_fields' , 'remove_company_name' );
function remove_company_name( $fields ) {
    $company = $fields['billing']['billing_private_company'];
    if ($company < 2) {
     unset($fields['billing']['billing_company']);
     return $fields;
    } 
     return $fields;
}

What am I doing wrong? Thanks in advance for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source