Display SKU on Cart Page in Woocommerce

Display SKU on Cart Page in Woocommerce

If you have an e-commerce website with woocommerce function, then in cart page it shows only items on it. When there are products with same name having different SKU added in cart, you can not differentiate it in woocomerce cart page.

Display SKU on Cart Page in Woocommerce,sjow sku on cart page, Vivid Techno Best Web Company India

Following is the solution to Display SKU on Cart Page in Woocommerce:

// 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;
}

add above code into function.php of child theme of selected theme.

For more Info call +919811442146 or write a mail to sales.vividtechno@gmail.com

Leave a Comment

Your email address will not be published.

Shopping Cart