skip to Main Content

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

3

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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

    Login or Signup to reply.
  3. 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' );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search