Skip to content
Advertisement

Show SKU on cart and checkout pages in Woocommerce 3

I would like to display SKU on cart (Under product column ) and checkout page.

I searched SO, but all answers are for old versions of WooCommerce and non of them is for 3.x.

How can I show SKU on cart and checkout pages in Woocommerce 3?

Advertisement

Answer

2021 Update

You can do it with a custom unction hooked in woocommerce_cart_item_name action hook, this way:

// Display the sku below cart item name
add_filter( 'woocommerce_cart_item_name', 'display_sku_after_item_name', 5, 3 );
function display_sku_after_item_name( $item_name, $cart_item, $cart_item_key ) {
    $product = $cart_item['data']; // The WC_Product Object

    if( is_cart() && $product->get_sku() ) {
        $item_name .= '<br><span class="item-sku">'. $product->get_sku() . '</span>';
    }
    return $item_name;
}

// Display the sku below under cart item name in checkout
add_filter( 'woocommerce_checkout_cart_item_quantity', 'display_sku_after_item_qty', 5, 3 );  
function display_sku_after_item_qty( $item_quantity, $cart_item, $cart_item_key ) {
    $product = $cart_item['data']; // The WC_Product Object

    if( $product->get_sku() ) {
        $item_quantity .= '<br><span class="item-sku">'. $product->get_sku() . '</span>';
    }
    return $item_quantity;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works on WooCommerce 3+. You will get:

enter image description here

And

enter image description here

Related similar: How to Show SKU with product title in Order received page and Email order

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement