最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Where do I remove admin order fields (unset doesn't work)

programmeradmin0浏览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.

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.

Share Improve this question edited May 28, 2020 at 15:39 Slingy asked May 28, 2020 at 15:25 SlingySlingy 311 silver badge5 bronze badges 2
  • 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 Commented May 28, 2020 at 15:29
  • @TonyDjukic i have updated my question. – Slingy Commented May 28, 2020 at 15:39
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论