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

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

by adminkys

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 tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 5
 * @donate $9     https://www.tutoraspire.com
 */

// First, let's write the function that returns a given product SKU
function tutoraspire_return_sku( $product ) {
   $sku = $product->get_sku();
   if ( ! empty( $sku ) ) {
return '

SKU: ' . $sku . '

'; } else { return ''; } } // This adds the SKU under cart/checkout item name add_filter( 'woocommerce_cart_item_name', 'tutoraspire_sku_cart_checkout_pages', 9999, 3 ); function tutoraspire_sku_cart_checkout_pages( $item_name, $cart_item, $cart_item_key ) { $product = $cart_item['data']; $item_name .= tutoraspire_return_sku( $product ); return $item_name; } // This adds SKU under order item table name add_action( 'woocommerce_order_item_meta_start', 'tutoraspire_sku_thankyou_order_email_pages', 9999, 4 ); function tutoraspire_sku_thankyou_order_email_pages( $item_id, $item, $order, $plain_text ) { $product = $item->get_product(); echo tutoraspire_return_sku( $product ); }

You may also like