Search code examples
phpwordpresswoocommercehook-woocommerceorders

Change order item displayed meta key label in WooCommerce admin order pages


Following Display a product custom field only in WooCommerce Admin single orders answer to my previous question, which:

  1. Adds a Custom SKU Field (ArticleID)
  2. Saves the Custom SKU (ArticleID) as Hidden Order Item Meta Data
  3. Saves the Custom SKU (ArticleID) as Hidden Order Item Meta Data for Manual Orders

How can I change the displayed meta key label _articleid on order line items section of the admin single order pages?

Right now it shows the "SKU", the "Variation ID" (for product variations) and the "_articleid".

I'd like to replace displayed "_articleid" with "Article ID" instead.

Any help?


Solution

  • You will use the following to replace displayed key label _articleid with for example 'Article ID' in order items on WooCommerce admin single orders:

    add_filter('woocommerce_order_item_display_meta_key', 'filter_wc_order_item_display_meta_key', 20, 3 );
    function filter_wc_order_item_display_meta_key( $display_key, $meta, $item ) {
    
        // Change displayed label for specific order item meta key
        if( is_admin() && $item->get_type() === 'line_item' && $meta->key === '_articleid' ) {
            $display_key = __("Article ID", "woocommerce" );
        }
        return $display_key;
    }
    

    Code goes in functions.php file of the active child theme (or active theme). It should works.

    Related:

    Change order item custom meta data displayed label and value in WooCommerce Admin orders

    Related to this thread: