1

I was under the impression that if you add an underscore to your meta_key, it would be hidden from the Admin and subsequently the Order Receipts, etc.

But, mine are showing? I don't understand what's going on...

meta_key: _testing_this, meta_value: asdasdasd

How do I added order item meta without it showing up?

3 Answers 3

5

You'll want to add to the hidden item meta array as such:

add_filter('woocommerce_hidden_order_itemmeta', 
   array($this, 'hidden_order_itemmeta'), 50);

function hidden_order_itemmeta($args) {
  $args[] = 'my_hidden_meta';
  return $args;
}
0

The answer is to serialize the data you want to be hidden for sure.

0

My solution:

//remove order item meta key
        add_filter( 'woocommerce_order_item_get_formatted_meta_data', 'mobilefolk_order_item_get_formatted_meta_data', 10, 1 );

function mobilefolk_order_item_get_formatted_meta_data($formatted_meta){
        $temp_metas = [];
        foreach($formatted_meta as $key => $meta) {
            if ( isset( $meta->key ) && ! in_array( $meta->key, [
                    'lyric_id',
                    'lyric_song_title',
                    'lyric_artist_name'
                ] ) ) {
                $temp_metas[ $key ] = $meta;
            }
        }
        return $temp_metas;
    }
2
  • You should add a helpful content to better understand the solution without reading the source.
    – bueltge
    Aug 16, 2017 at 11:21
  • I think it's enough easy to understand for anyone.
    – Hà Bầu
    Aug 17, 2017 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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