skip to Main Content

I’ve taken over my companies WordPress site after the web company we used went bust. I’m not a strong programmer, so bare with me. I’m trying to edit the metadata fields on our WooCommerce admin order page. For example, where it says "_user_handle_rebate", I need it to say "Handle Rebate". I’ve looked for this with a string finder and I can only see this in the order-details.php file, which is not seemingly where this is coded after trying to change the name. Lots of googling has suggested this may be in the functions.php file, but I’m still at a loss of what to look for.

enter image description here

Is there a snippet of code I can add to change this after the fact or do I have to change this value when it is stored. Any advice is much appreciated.

I’ve tried editing the metadata fields in the order-details.php file, but this has no effect on the admin order page. I’ve also tried looking in the functions.php, but to no avail. This is the only code I can find with a string finder:

do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );

echo "<br/>";
if (!empty($item_meta->meta['_user_width'][0]))
    echo "Width: ". $item_meta->meta['_user_width'], $item_meta->meta['_user_unit'] ."<br/>";
if (!empty($item_meta->meta['_user_drop'][0]))
    echo "Drop: ". $item_meta->meta['_user_drop'], $item_meta->meta['_user_unit'] ."<br/>";
if (!empty($item_meta->meta['_user_fitting'][0]))
    echo "Fitting Type: ". $item_meta->meta['_user_fitting'] . "<br/>";
if (!empty($item_meta->meta['_user_pull']))
    echo "Pull side: ". $item_meta->meta['_user_pull'] ."<br/>";
if (!empty($item_meta->meta['_user_chain']))
    echo "Chain Type: ". $item_meta->meta['_user_chain'] ."<br/>";
if (!empty($item_meta->meta['_user_tilt'][0]))
    echo "Tilt side: ". $item_meta->meta['_user_tilt'] ."<br/>";
if (!empty($item_meta->meta['_user_controls'][0]))
    echo "Controls: ". $item_meta->meta['_user_controls'] ."<br/>";
if (!empty($item_meta->meta['_user_stack'][0]))
    echo "Stack side: ". $item_meta->meta['_user_stack'] ."<br/>";
if (!empty($item_meta->meta['_user_bracket'][0]))
    echo "Bracket fitting side: ". $item_meta->meta['_user_bracket'] ."<br/>";
if (!empty($item_meta->meta['_user_opening'][0]))
    echo "Control Wand: ". $item_meta->meta['_user_opening'] ."<br/>";
if (!empty($item_meta->meta['_user_frame_colour'][0]))
    echo "Frame colour: ". $item_meta->meta['_user_frame_colour'] ."<br/>";
if (!empty($item_meta->meta['_user_operation_type'][0]))
        echo "Operation Type: ". $item_meta->meta['_user_operation_type'] ."<br/>";
if (!empty($item_meta->meta['_user_depth'][0]))
    echo "Depth: ". $item_meta->meta['_user_depth'] ."<br/>";
if (!empty($item_meta->meta['_user_handle_rebate']))
{
    echo "Handle Rebate Location: ". $item_meta->meta['_user_handle_rebate'];
    echo '<br/>Measurements: ' . $item_meta->meta['_user_hr_measurements'].' mm';
}

2

Answers


  1. Chosen as BEST ANSWER

    Stumbled on some code of yours @LoicTheAztec from 2021, seems to have done the trick!

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

  2. In WooCommerce admin single order pages, to change any displayed meta key to a readable label name replacement, use the following:

    // Change order items displayed meta key(s) to readable label name(s) replacement(s)
    add_filter('woocommerce_order_item_display_meta_key', 'add_readable_meta_keys_names_replacements', 10, 3 );
    function add_readable_meta_keys_names_replacements( $display_key, $meta, $item ) {
        // Only for "line_item" order item type
        if( $item->get_type() === 'line_item' ) 
            return $display_key;
    
        // Handle Rebate
        if( $meta->key === '_user_handle_rebate' ) {
            $display_key = esc_html__('Handle Rebate', 'woocommerce');
        }
    
        // Measurements
        elseif( $meta->key === '_user_hr_measurements' ) {
            $display_key = esc_html__('Measurements', 'woocommerce');
        }
    
        return $display_key;
    }
    

    Code goes in functions.php file of your child theme (or in a plugin). It should work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search