Reputation: 53
I am trying to append text to the SKU when a sample is ordered.
I have tried the following code to modify the title,
function cart_title($title, $values, $cart_item_key){
if ($values['sample']){
$title .= ' [' . __('Sample','woosample') . '] ';
}
return $title;
}
How do I modify this code to change the SKU?
Upvotes: 3
Views: 144
Reputation: 29624
note: woocommerce_cart_item_name will not display in the backend order view
function cart_title( $title, $cart_item, $cart_item_key ) {
$product = $cart_item['data'];
$product_sku = $product->get_sku();
// optional
if ( empty( $product_sku ) ) {
$product_sku = 'not found!';
}
$title = $title . ' + ' . $product_sku;
return $title;
}
add_filter('woocommerce_cart_item_name', 'cart_title', 10, 3 );
Upvotes: 1