I'm trying to change the name of the product in cart and checkout pages.
I have the following code to add some cart meta data:
function render_meta_on_cart_and_checkout( $cart_data, $cart_item = null ) {
$custom_items = array();
/* Woo 2.4.2 updates */
if( !empty( $cart_data ) ) {
$custom_items = $cart_data;
}
if( isset( $cart_item['sample_name'] ) ) {
$custom_items[] = array( "name" => $cart_item['sample_name'], "value" => $cart_item['sample_value'] );
}
return $custom_items;
}
add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );
But I also want to change the name of the product.
For example if the product name is Apple
and custom field 'sample_value'
value is with sugar
, I would like to get Apples (with sugar)
.
How can I achieve this?