How to update cart attributes when "buy it now" button is clicked from theme app extension?

The liquid code given in https://shopify.dev/docs/api/liquid/objects/cart only works for when we use “Checkout” button on the cart page. Is there any way to update cart attributes using Javascript without the need to press any button or when “buy it now” button is pressed?

Hi @Sam9516

Please refer to the below article on how you can use CART API.

https://shopify.dev/docs/api/ajax/reference/cart#private-properties-and-attributes

In short, you can use the below script to push data in the cart attribute.

jQuery.post(window.Shopify.routes.root + 'cart/update.js', { attributes: {'repeat order':'BAC' } },function(){
     window.location.href = '/cart';
});

My code assumes that you have jQuery installed in store.