I would like to display SKU on cart (Under product column ) and checkout page.
I searched SO, but all answers are for old versions of WooCommerce and non of them is for 3.x.
How can I show SKU on cart and checkout pages in Woocommerce 3?
2021 Update
You can do it with a custom unction hooked in woocommerce_cart_item_name
action hook, this way:
// Display the sku below cart item name
add_filter( 'woocommerce_cart_item_name', 'display_sku_after_item_name', 5, 3 );
function display_sku_after_item_name( $item_name, $cart_item, $cart_item_key ) {
$product = $cart_item['data']; // The WC_Product Object
if( is_cart() && $product->get_sku() ) {
$item_name .= '<br><span class="item-sku">'. $product->get_sku() . '</span>';
}
return $item_name;
}
// Display the sku below under cart item name in checkout
add_filter( 'woocommerce_checkout_cart_item_quantity', 'display_sku_after_item_qty', 5, 3 );
function display_sku_after_item_qty( $item_quantity, $cart_item, $cart_item_key ) {
$product = $cart_item['data']; // The WC_Product Object
if( $product->get_sku() ) {
$item_quantity .= '<br><span class="item-sku">'. $product->get_sku() . '</span>';
}
return $item_quantity;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works on WooCommerce 3+. You will get:
And
Related similar: How to Show SKU with product title in Order received page and Email order
You'll need to do some template overrides.
Cart
Copy plugins/woocommerce/templates/cart/cart.php
into your theme file at my_theme/woocommerce/cart/cart.php
if it isn't already there. Then add the following at approx line #85
// Meta data
// (this is already in cart.php; look for it for where to place the next snippet)
echo WC()->cart->get_item_data( $cart_item );
// Add SKU below product name
if ( !empty($_product->get_sku()) ) { ?>
<div class="sku">
<small><?php echo "SKU: ". $_product->get_sku(); ?></small>
</div>
<?php }
Checkout
Copy plugins/woocommerce/templates/checkout/review-order.php
into your theme file at my_theme/woocommerce/checkout/review-order.php
if it isn't already there. Then add the following at approx line #43
<?php
// (this is already in review-order.php; look for it for where to place the next snippet)
echo WC()->cart->get_item_data( $cart_item ); ?>
<?php
// Add SKU below product name
if ( !empty($_product->get_sku()) ) { ?>
<div class="sku">
<small><?php echo "SKU: ". $_product->get_sku(); ?></small>
</div>
<?php } ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With