Show SKU @ Cart Page

woocommerce show sku cart page

When SKU matters to the end users, then displaying it in the Cart page under each item’s name is a must.

Ideal for B2B businesses and international brands, this simple edit can actually help you learn how to add any sort of content under the Cart item names. Simply use the same hook and maybe try to get something different than SKU with this guide. Enjoy!

woocommerce show sku cart page
With this handy snippet, echoing the SKU under each item in the Cart page is a breeze!

PHP Snippet: Display SKU Below Item Names @ Cart

/**
 * @snippet       Show SKU @ WooCommerce Cart
 * @author        PHP - Stackoverflow
 * @testedwith    WooCommerce 4.1
 */

add_action( 'woocommerce_after_cart_item_name', 'phpsof_sku_below_cart_item_name', 11, 2 );

function phpsof_sku_below_cart_item_name( $cart_item, $cart_item_key ) {
	$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
	$sku = $_product->get_sku();
	if ( ! $sku ) return;
	echo '<p><small>SKU: ' . $sku . '</small></p>';
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before “?>” if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files – if you need more guidance, please take a look at my free video tutorial “Where to Place WooCommerce Customization?”

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, feel free to join 10,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance 🙂

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins via your child theme. Watch me code and learn by example!

Leave a Reply

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