Customize Checkout - Collect extra product/order information

New Member
2 0 0

Hi,

I want to somehow intercept the "Buy Now" button and store an additional piece of data in a hidden field in the order.

I assume there is some way, using JQuery, to prevent to default action of the "buy now" button to do this before it submits?

So, somehow I need to be able to

  1. Add a hidden field to the order form. Which will be available in the order webook/admin area.
  2. Intercept the action of the "Buy Now" button.

I am new to Shopify development so apologies for my lack of knowledge.

Any help would be greatly appreciated.

0 Likes
Highlighted
Trailblazer
208 1 101

Look into cart[attributes] field.

https://shopify.dev/docs/themes/liquid/reference/objects/cart

Two ways you can get data in this field, which then gets stored on the cart / checkout / order object and shows up in the shopify admin

 

Here's an example of the field you need to populate in your add to cart form, or on your /cart page form. This data will get passed into order.

<input id="attr-myfield" type="hidden" name="attributes[myfield]" value="my fields value" />

 

As for hooking into the "Buy Now" button, that's something you'll need to do with javascript by hooking into onsubmit.

0 Likes