0

I have built shop based on Woocommerce. In admin order, I need to disable state field. It shows state code, not full name, so it doesn't really matter.

When you enter certain order in admin page, you will get Billing and Shipping colums.

So basically, this snippet should do, but it doesnt. It removes fields in "edit" view.

add_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 1, 1 );
function custom_admin_billing_fields( $billing_fields ) {
   unset($billing_fields['state']);
   return $billing_fields;
}

Edit: Here are the screenshots to better understand my problem

As you can see, there is no "state" field, but number 2 (which is state id) shows.

enter image description here enter image description here

  • I'm not clear on the difference between 'edit' and 'admin' - all of the edit screens are in the admin section. Can you clarify the difference? – Tony Djukic May 28 at 15:29
  • @TonyDjukic i have updated my question. – Slingy May 28 at 15:39
0

Maybe try this:

function custom_admin_billing_fields( &$billing_fields ) {
   unset($billing_fields['state']);
}

It's not clear if when the custom_admin_billing_fields function is called if its return is actually captured and used. So it's possible that the return is ignored.

The ampersand (&) in the parameter definition makes that variable "by reference" instead of "by value". This way any changes made to this variable in the function will always be returned and affect the original variable passed.

| improve this answer | |
  • Sadly it doens't change much. My function actually works, as you can see on the first screenshot, but it doens't affect right input i guess. – Slingy May 28 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.