WooCommerce: Adding Order Item Meta Data That's Hidden

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?

Topic underscore woocommerce-offtopic post-meta Wordpress

Category Web


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;
}

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;
    }

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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.