Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide meta data from Order Items on Admin Order Page (WooCommerce)

I am using some custom Item Meta for products sold on my WooCommerce store. I am looking for a way to hide the item meta from showing up on the Admin Order page, under the order items section.

I am using underscores for the meta name, however the meta is still showing up.

You can see in the attached image what I mean...

Thoughts?

enter image description here

like image 437
Chris Hawkins Avatar asked May 04 '15 21:05

Chris Hawkins


2 Answers

You can try this:

function custom_woocommerce_hidden_order_itemmeta($arr) {
    $arr[] = '_xchange_code';
    return $arr;
}

add_filter('woocommerce_hidden_order_itemmeta', 'custom_woocommerce_hidden_order_itemmeta', 10, 1);
like image 108
christian Nguyen Avatar answered Nov 17 '22 21:11

christian Nguyen


//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;
}
like image 21
Hà Bầu Avatar answered Nov 17 '22 23:11

Hà Bầu