Pricing Process Reviews Contact

Divi Guy blog

Display the sku below cart item name in WooCommerce

Display the sku below cart item name in WooCommerce. There are 2 functions below. One is for the Cart page and the other is for the Checkout page.

/* Display the sku below cart item name on Cart BEGIN */

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 cart item name on Cart END */

/* Display the sku below under cart item name in checkout BEGIN */

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>SKU: <span class="item-sku">'. $product->get_sku() . '</span>';

    }

    return $item_quantity;

}

/* Display the sku below under cart item name in checkout END */

Need a hand?

Need help with your Divi website?

Book a Divi consultation and we can fix it together over Zoom, or ask for an estimate for bigger jobs.

0 Comments

Submit a Comment

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

Search

Browse

More tips

Got a question?

Ask me anything

Stuck on something in Divi or WordPress? Ask away and I will reply by email, usually within 24 hours.

Ask a Question

Tell me about your project. The more details the better.

"*" indicates required fields

Make a payment

Got an invoice?

Pay an invoice, a deposit or a tip in about a minute. Card or PayPal, secure checkout, and I never see your card number.

Make a payment