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...
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityAdd 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;
}
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.