Chris Hawkins
Chris Hawkins

Reputation: 451

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

Upvotes: 5

Views: 7011

Answers (2)

Hà Bầu
Hà Bầu

Reputation: 91

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

Upvotes: 2

christian Nguyen
christian Nguyen

Reputation: 1600

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

Upvotes: 16

Related Questions