How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?

We are developing a B2B shop with WooCommerce.

I want to show the SKU and the product dimensions underneath the product title in the cart.

This is what I have right now:

add_filter( ‘woocommerce_cart_item_name’, ‘add_sku_in_cart’, 20, 3);
function add_sku_in_cart( $title, $values, $cart_item_key ) {
$sku = $values[‘data’]->get_sku();
$dimensions = $values[‘data’]->get_dimensions();
return $sku ? $title . sprintf(” <br><span class=’articlenumber’>Artikelnummer: %s</span>”, $sku) : $title;
return $dimensions ? $title . sprintf(” <br><span class=’measurements’>Maße: %s</span>”, $dimensions) : $title;
}

Someone already told me that 2 returns won´t work and that I need a string. But since I am very new to PHP, I don´t know how to do it. Could someone please help me with that?

Thank you in advance and have a great day.

Read more here:: How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?

Leave a Reply

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