Add product form field to check for existing order number in system upon Add To Cart

I am building out a store that requires customers to have an existing order in the system to purchase other products. To provide context, the existing order contains artwork that has been purchased previously. With a valid order number, we grab the artwork associated with that order and print it on the product they are purchasing.

I’d like to configure an additional field in the product form that checks for an existing order number in the system. If the customer enters a valid order number the product is added to cart, if not, an error message is returned, “no order in system,” and the product is not added to cart.

I am looking for instructions on how to add that functionality to the product order form.

Thank you.

Hi @Michael_Boardm1 you can loop though customer orders in liquid code and save the order ids somewhere in frontend (maybe javascript json/array) https://shopify.dev/docs/api/liquid/objects/customer#customer-orders

And on add to cart event you can check and do whatever you want

Thanks Arunme. That’s an ideal scenario. After giving the idea some more thought, I opted to use that logic in association with customer accounts. To shop our products, the customer has to have at least one art order in the system. He can then apply the art from that order to the printed product he is ordering, say a printed mug. With the customer logged in, I can easily loop through all of that customer’s orders. Using metafields I can flag all art orders in the system as art. Then, when I loop through the orders, I can do 2 things:

  1. Expose the Add To Cart button when I find an order where ‘art’ = true.
  2. Provide a dropdown menu of all orders where ‘art’ = true, including thumbnail of the art, so a customer can select which art item to print on the product. I can then pass that selection as a line item property to the cart.