T
T
trenton2021-02-15 05:21:54
WooCommerce
trenton, 2021-02-15 05:21:54

How to properly disable fields in the checkout, so as not to scream about the address?

So far, only one solution has come up to me - to make the fields optional just like this

add_filter( 'woocommerce_checkout_fields', 'unrequire_checkout_fields' );
function unrequire_checkout_fields( $fields ) {
  $fields['billing']['billing_company']['required']   = false;
  $fields['billing']['billing_city']['required']      = false;
  $fields['billing']['billing_postcode']['required']  = false;
  $fields['billing']['billing_country']['required']   = false;
  $fields['billing']['billing_state']['required']     = false;
  $fields['billing']['billing_address_1']['required'] = false;
  $fields['billing']['billing_address_2']['required'] = false;
  return $fields;
}

And only hide with css
#billing_country_field, #billing_address_1_field, #billing_address_2_field,#billing_state_field,#billing_last_name_field,#billing_postcode_field,#billing_company_field {
        display: none !important;
      }

But I think it's VERY inflexible. As soon as I insert it like this, it infuriates with its "enter the address", and also the "wrong delivery method" regarding the native pickup. With that, and like this, a completely separate action, and in that hook just unset($fields['billing']..... fields without hanging a new action before return.
add_filter('woocommerce_checkout_fields','remove_checkout_fields');
function remove_checkout_fields($fields){
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    return $fields;
}

It is without these lines with css that everything is sent as it should, and it is on them that it swears, I have already double-checked it many times. Maybe someone had and somehow decided, understood what the conflict is?
I mean natively, plug-ins then it is clear that there is a wagon.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question