Reputation: 387
I've looked all over and haven't figured this out, but am close. I purchased the Woocommerce wishlist and I am trying to have the SKU as well as price, quantity, etc.
I found this code to add to the functions.php file:
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;
}
However I don't know how to use the function in the cart or wishlist file. I'm practicing in the Cart and assume that the Wishlist would be the same.
I tried YITH Wishlist plugin and was successful in getting the SKU to that wishlist using this code (thanks to skrilled):
<?php echo $product_obj->get_sku(); ?>
However, that same code does not seem to work using the Woocommerce Wishlist plugin.
Thanks.
Upvotes: 1
Views: 1921
Reputation: 11808
For woocommerce wishlist plugin:
add_filter("woocommerce_in_cartproduct_obj_title", "wdm_test", 10 , 2);
function wdm_test($product_title, $product){
if(is_a($product, "WC_Product_Variation")){
$product_test = new WC_Product($product->variation_id);
return $product_title . " " . $product_test->get_sku();
}
elseif( is_a($product, "WC_Product") ){
$product_test = new WC_Product($product->id);
return $product_title . " " . $product_test->get_sku();
}
else{
return $product_title ;
}
}
Upvotes: 1