Is it possible?

So i want a functionality that after user has placed order he gets a ready to pick button through which i am getting user’s lat and long and want to save as a metafields at user’s particular order. Is it possible and if yes from frontend?

Yes, it is possible to capture data and save it as an order metafield. You’d add this functionality using Shopify’s Storefront API which allows you to manage customer’s data including metafields.

Just to confirm - are you getting the customer to manually enter their own values for lat and long?If so, after getting the user’s latitude and longitude upon clicking the ‘Ready to Pick’ button, you’ll need to make a POST request to the Shopify Storefront API’s checkoutCreate mutation with the cart information. This will create a new checkout object.

Then, you can use the checkoutCustomerAssociateV2 mutation to associate the customer with the checkout. Once the order is placed, you can use the metafieldCreate mutation to create a new metafield and associate it with the specific order. You’d store the latitude and longitude data in this metafield.

Here’s an example of how to create a metafield for an order:

mutation {
  metafieldCreate(input: {
    namespace: "custom_fields",
    key: "latitude",
    valueInput: "51.5074",
    valueType: STRING,
    ownerType: ORDER,
    ownerId: "gid://shopify/Order/1234567890"
  }) {
    metafield {
      id
    }
    userErrors {
      field
      message
    }
  }
}

Please note that you need to replace "51.5074" with your latitude data and "gid://shopify/Order/1234567890" with the actual GraphQL ID of the order. Keep in mind that while you can create metafields from the frontend, it’s generally a good idea to handle this logic on the server-side to keep the app secure and performant.

Hope this helps!