1

How to show the SKU next to the product name in the cart page of Woocommerce ?

tried to copy it from the Meta.php of single product but it breaks the page...

2 Answers 2

2

Add the following code to your theme's functions.php file, or as a new plugin:

add_filter( 'woocommerce_in_cart_product_title', 'add_sku_in_cart', 20, 3);

function add_sku_in_cart( $title, $values, $cart_item_key ) {
  $sku = $values['data']->get_sku();
  return $sku ? $title . sprintf(" (SKU: %s)", $sku) : $title;
}
1
  • Cheers @GM, works a treat.
    – dan
    Aug 1, 2013 at 4:03
3

For those finding this from google, here code that works on current versions (2.1+) of WooCommerce.

add_filter( 'woocommerce_cart_item_name', 'add_sku_in_cart', 20, 3);

function add_sku_in_cart( $title, $values, $cart_item_key ) {
    $sku = $values['data']->get_sku();
    return $sku ? $title . sprintf(" (SKU: %s)", $sku) : $title;
}

The code example from G.M. did not work for me, and my rep is too low to comment on his post.

Source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.