Show SKUs in the Cart, Checkout and Orders
Prints each product's SKU under its name in the cart, checkout and order details, which trade buyers and phone orders often need.
Opens WPIDE on
Code
add_filter( 'woocommerce_get_item_data', function ( $data, $item ) {
$sku = isset( $item['data'] ) ? $item['data']->get_sku() : '';
if ( $sku ) {
$data[] = array( 'key' => 'SKU', 'value' => $sku );
}
return $data;
}, 10, 2 );
add_action( 'woocommerce_order_item_meta_start', function ( $item_id, $item ) {
$product = is_callable( array( $item, 'get_product' ) ) ? $item->get_product() : null;
if ( $product && $product->get_sku() && ! is_admin() ) {
printf( '<br><small class="wpide-item-sku">SKU: %s</small>', esc_html( $product->get_sku() ) );
}
}, 10, 2 );
Notes
Variations show their own SKU, or the parent's if they have none.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.