Alex
Alex

Reputation: 11

How to hide some Custom Fields from Woocommerce Admin order page

When logged in as an admin and looking at an Order in Woocommerce, there's a section with all the Custom Fields. Out of the whole list I only want it to display two of them. How do I hide the rest from this view? I don't want to delete them, but just hide from this view.

enter image description here

Upvotes: 0

Views: 1434

Answers (3)

Moalla
Moalla

Reputation: 11

For orders in Woocommerce the post type is 'shop_order', so your code should be:

add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
    remove_meta_box( 'postcustom', 'shop_order', 'normal' );
}

Upvotes: 1

Kiriakos Grhgoriadhs
Kiriakos Grhgoriadhs

Reputation: 319

if you’re using ACF pro, there is a hook you can use to remove the field on the back end, but it’s not something that’s documented..

You could use a hook to remove specific field if is_admin() returns true.

You may need to play with this a bit to get it to work, the ACF hook is

acf/get_fields  

So, for example:

add_filter('acf/get_fields', 'your_function_name', 20, 2);
function your_function_name($fields, $parent) {
  // remove the fields you don't want
  return $fields;
}

$fields can be a nested array of fields => sub_fields.

You need to set the priority > 10 to run after the internal ACF filter

Upvotes: 0

Alex
Alex

Reputation: 11

For every custom field you want hidden, add the following 4 lines of code to functions.php or using Snippets plugin:

    add_filter('is_protected_meta', 'my_is_protected_meta_filter1', 10, 2);
    function my_is_protected_meta_filter1($protected, $meta_key) {
        return $meta_key == 'automatewoo_cart_id' ? true : $protected;
    }

If you want to hide more than one, add the lines above again and change 'my_is_protected_meta_filter1' to 'my_is_protected_meta_filter2', etc

Upvotes: 0

Related Questions