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

五迷三道 提交于 2021-02-04 07:28:06

问题


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?


回答1:


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:

  • How to show a product custom field (custom SKU) in WooCommerce orders
  • Display a product custom field only in WooCommerce Admin single orders for Manual Orders


来源:https://stackoverflow.com/questions/65893733/change-order-item-displayed-meta-key-label-in-woocommerce-admin-order-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!