Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
602 views
in Technique[技术] by (71.8m points)

php - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...