Scroll to top

How to show SKU on cart and checkout page in woocommerce

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 🙂

Share Post:
Author avatar
Zahid Iqbal
I am a web designer and developer working full-time.

3 comments

  1. John

    not working in latest wp/woo

  2. Lyse

    Just added it to my functions.php file and it works like a charm.
    Thank you for sharing.

Post a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.