1

using woocommerce and before I would just use this code to have sku number show up on cart page. I would just add it in the functions.php

add_filter( 'woocommerce_in_cart_product_title', 'add_sku_in_cart', 20, 3);
function add_sku_in_cart( $title, $values, $cart_item_key ) {
  $sku = $values['data']->get_sku();
  return $sku ? $title . sprintf(" (SKU: %s)", $sku) : $title;
}

Now I get this Fatal error: Call to a member function get_sku() on a non-object in

I updated both my theme and woocommerce to latest version and then it erased the custom codes.

nufftalon
  • 25
  • 6

1 Answers1

0

You can try adding this $product_obj->get_sku();

Ryan NZ
  • 616
  • 1
  • 9
  • 25
  • Hi it doesn't seem to work for me when I add it, it gives same error. – nufftalon Apr 10 '14 at 18:49
  • add_filter( 'woocommerce_in_cart_product_title', 'add_sku_in_cart', 20, 3); function add_sku_in_cart( $title, $values, $cart_item_key ) { $sku = $values['data']->$product_obj->get_sku(); return $sku ? $title . sprintf(" (SKU: %s)", $sku) : $title; } – nufftalon Apr 10 '14 at 18:51
  • how about echoing all of the variables to see what isnt populating? echo $values'. '.$cart_item_key.' '.$values['data'] etc? – Ryan NZ Apr 10 '14 at 22:07