Hi friends,
I was working on a project where we need to show product sku code after product title in cart and checkout pages. Our theme was custom built so it doesn’t has this feature by default. So, we have to code to get the work done.
Below is the final code that you will insert in your active theme’s functions.php file at the end. Please note that this code works only for woocommerce versions 3.0+.
/*
* Show SKU after product title in cart page
*/
add_filter( 'woocommerce_cart_item_name', 'mzi_showing_sku_in_cart_items', 99, 3 );
function mzi_showing_sku_in_cart_items( $item_name, $cart_item, $cart_item_key ) {
// The WC_Product object
$product = $cart_item['data'];
// Get the SKU
$sku = $product->get_sku();
// When sku doesn't exist
if(empty($sku)) return $item_name;
// Add the sku
$item_name .= '<br><small class="product-sku">' . __( "SKU: ", "woocommerce") . $sku . '</small>';
return $item_name;
}
Happy coding 🙂
John
not working in latest wp/woo
Lyse
Just added it to my functions.php file and it works like a charm.
Thank you for sharing.
Zahid Iqbal
You are welcome 🙂