I have added a custom field in my cart object when a product is added to the cart using this filter:

add_filter( 'woocommerce_add_cart_item_data', 'custom_field_add_cart_item_data', 10, 2 );

function custom_field_add_cart_item_data( $cart_item, $product_id ){

$items = WC()->cart->get_cart();
$custom_field = [1 => 'test'];

$cart_item['custom_field'] = $custom_field;

return $cart_item;

That works fine when getting the array value (custom_field) in my cart.

In the cart, i have to update the array (custom_field) value using ajax.

Any idea how this is achievable? Any woocommerce hack i can use?

the codes in the ajax function:

$array = [];
$array[$cart_item_key]['custom_field'] = [1 => 'test updated'];

I tried this one but to no avail! :/ Can someone help me please?

Your Answer


Browse other questions tagged or ask your own question.