WooCommerce: Show SKU @ Cart, Checkout, Order & Emails

When SKU matters to the end user, displaying it in the Cart page, Checkout page, Thank you page, My Account View Order page and Order Emails under the item name is a must.

Ideal for B2B businesses and international brands, this simple customization can help you learn how to add any sort of content under the Cart/Checkout/Order item names. Simply use the same hook and try “getting” something different than SKU with this guide. Enjoy!

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, Checkout, Order, Emails

/**
 * @snippet       Show SKU @ WooCommerce Cart
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 5
 * @community     https://businessbloomer.com/club/
 */

// First, let's write the function that returns a given product SKU
function bbloomer_return_sku( $product ) {
   $sku = $product->get_sku();
   if ( ! empty( $sku ) ) {
		return '<p>SKU: ' . $sku . '</p>';
	} else {
		return '';
	}
}

// This adds the SKU under cart/checkout item name
add_filter( 'woocommerce_cart_item_name', 'bbloomer_sku_cart_checkout_pages', 9999, 3 );

function bbloomer_sku_cart_checkout_pages( $item_name, $cart_item, $cart_item_key  ) {
	$product = $cart_item['data'];
   $item_name .= bbloomer_return_sku( $product );
   return $item_name;
}

// This adds SKU under order item table name
add_action( 'woocommerce_order_item_meta_start', 'bbloomer_sku_thankyou_order_email_pages', 9999, 4 );

function bbloomer_sku_thankyou_order_email_pages( $item_id, $item, $order, $plain_text ) {
	$product = $item->get_product();
   echo bbloomer_return_sku( $product );
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • WooCommerce: Remaining $$$ to Get Free Shipping Notification @ Cart
    This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to the cart in order to qualify for free shipping. It’s pure psychology. So, here’s how we show a simple message on […]
  • WooCommerce: Add Content to a Specific Order Email
    Customizing WooCommerce emails via the WordPress dashboard is not easy and – sometimes – not possible. For example, you can’t edit or add content to them unless you’re familiar with code. Well, here’s a quick example to learn how to add content to any WooCommerce default order email. In this case study, our goal is […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

30 thoughts on “WooCommerce: Show SKU @ Cart, Checkout, Order & Emails

  1. How show SKU and other custom fields like: Barcode and BBE to a child product from grouped ones? At the moment natively Woo shows only to select quantity, it’s name and price. Thanks

    1. Hello George, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi, Rodolfo.

    Thanks for your useful snippet!

    Recently, I noticed that this snippet works well except broking the “view order” page in my account page. When customer click the “view” button on the “view order” page, they will see an “There has been a critical error on this websit” error message.

    PS. I use Blocksy theme, WooCommerce 8.2.1, and have switched to default theme and deactivated all the other plugin to test this snippet~

    1. Sorry about the delay. Works fine on my test website. What does the Fatal Error say?

  3. Works perfectly for my site!

  4. Works like a charm! I’m using Riode Theme.

  5. Hi, Thank you for creating a very useful snippet to add SKU on cart, checkout, email and order detail pages. It is working correctly on Cart, checkout and order details page. However in an email, it is adding SKU value two times in this format.

    Product title (# SKU-value)
    SKU: SKU-value

    Any reason, why is it adding the value of SKU two times in an order confirmation email?

    1. Hi Manish, thanks for that! Do you use any email customizer plugin? If not, could you send me a screenshot?

        1. Thank you. Try adding this as well:

          add_filter( 'woocommerce_email_order_items_args', 'bbloomer_no_sku_admin_emails' );
          
          function bbloomer_no_sku_admin_emails( $args ) {
          	$args['show_sku'] = false;
          	return $args;
          }
          
          1. I’ve got the same problem, but than on the Cart page. So the SKU is after the title and also in a new paragraph.

            1. Try with:

              function bbloomer_sku_cart_checkout_pages( $item_name, $cart_item, $cart_item_key  ) {
                 $product = $cart_item['data'];
                 $item_name .= is_cart() ? : bbloomer_return_sku( $product );
                 return $item_name;
              }
              
              1. Hi there! I’ve got the same problem on the Cart page. The SKU is appearing in the title (inside the clickable link) and also in a new paragraph (without link).

                You can check this error here: https://prnt.sc/TOS03qs0sdyE

                I’ve tried to replace the “bbloomer_sku_cart_checkout_pages” function with the one you recommended above:

                function bbloomer_sku_cart_checkout_pages( $item_name, $cart_item, $cart_item_key  ) {
                   $product = $cart_item['data'];
                   $item_name .= is_cart() ? : bbloomer_return_sku( $product );
                   return $item_name;
                }

                And after this, the SKU’s at the cart aren’t appearing anymore, and instead the products received an “1” entry inside the title, and an “1” outside the title.

                You can check this new error here: https://prnt.sc/6_MMIEJ36Hc5

                Can you help me?

                1. Try with:

                  $item_name .= is_cart() ? '' : bbloomer_return_sku( $product );
                  1. Hey!

                    I’ve tried with this new change, and the “11” glitch is gone, but the SKU isn’t appearing too.

                    Can you help me?

                    1. Not 100% sure, must be your theme?

  6. It’s adding empty   code after SKU code.

    1. Weird, screenshot please?

  7. Hi is there any way to add a SKU on a email quote.

    1. Hi Kyle, what do you mean by “email quote”?

  8. Not working for me πŸ™ – using Avada theme…

    1. Not working anywhere? Avada may be customizing WooCommerce templates/function so it may need further customization

      1. Hello, has this issue been fixed for the Avada theme?

        1. Hi Drew, thanks so much for your comment! I’m afraid this is custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  9. It still works and it looks really nice. What about the checkout page (order summary)?

    1. Should work there too out of the box

  10. Yes it still works (2021). Works on the cart page/checkout but not on mini cart.

    1. Cool! The mini cart will require an additional piece of code

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

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