I have added custom cart item data to products upon adding to the cart via the following code:
$cartData = array("_weekly_booking_price" => $weeklyPrice);
WC()->cart->add_to_cart( $productId, 1, 0, $cartData );
This occurs in the woocommerce_store_api_register_update_callback
function when extensionCartUpdate
is called on the frontend.
What I want to happen is the custom cart item data to be displayed with the product in a human readable format. By default the label for the custom data renders the key for that data which is less than ideal
I have tested this with the the old shortcode based checkout which works as expected
I have tried using the following filter but this results in the custom data being rendered twice, once with the unreadable key _weekly_booking_price
and the second with a human readable label which is facilitated by the filter below.
function clean_get_item_data($item_data, $cart_item_data)
{
if (isset($cart_item_data['variation']['_weekly_booking_price'])) {
$item_data[] = array(
'key' => "Weekly booking price",
'value' => wc_clean($cart_item_data['variation']['_weekly_booking_price']),
);
}
return $item_data;
}
add_filter('woocommerce_get_item_data', 'clean_get_item_data', 10, 2);
Here’s what that looks like