Back

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:
Zahid Iqbal
Zahid Iqbal
I am a web designer and developer working full-time.

3 comments

Leave a Reply

Your email address will not be published. Required fields are marked *

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