In functions.php
add_action( 'woocommerce_add_order_item_meta', 'custom_add_item_sku', 10, 3 );
function custom_add_item_sku( $item_id, $values, $cart_item_key ) {
$item_sku = get_post_meta( $values[ 'product_id' ], '_sku', true );
wc_add_order_item_meta( $item_id, 'SKU', $item_sku , false );
}
But its showing SKU value below Product title but i want it like this
SKU:123sd - Product Name
Use woocommerce_order_item_name filter hook instead. I have make some changes in your code:
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested in WooCommerce 3+ and works.
Displaying the SKU in cart items name (Updated: with the link for cart page):
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested in WooCommerce 3+ and works.
I would change the hook to 'woocommerce_new_order_item' as it seems like there may be some deprecation issues with the 'woocommerce_add_order_item_meta'
Something like this should add the name after the SKU, but I don't know if that's exactly what you're looking for.