How to display products or variants metafields in line item of order admin page?

How to display products or variants metafields in line item of order admin page?

Joey1919
Tourist
3 0 3

Hi guys, I'm trying to find a way for the admin order page to also show each product's inventory pick location. We are small and only operates in one small warehouse, but each product are assigned to one drawer. We want our pickers to know which drawer to find the product, all from this page.

Currently, I'm thinking of storing the additional location (drawer number) information inside product metafields. But I'm stuck on how to display the product / variant metafields information inside the admin order page (as shown in the attached image below. 

 

Shopify Technical Q&A 1.png

 

Reply 1 (1)

Patane
Shopify Partner
15 2 1

@Joey1919 - This isn't a complete solution, but it should put you on the right track to figuring it out...

That light grey text you are seeing in the admin is the "line item properties" of the product. You'll want to pass the data that is in the variant's metafield to a line item property, which will get it to show in the admin. You can hide this line item property from the product page, and cart/checkout so your customers don't see it, but you will in the admin.

Being that each theme is different the implementation will vary, but with chatGPT, you can likely cobble this together.

 

Essentially you are looking for the product form, it typically looks something like this:

Screenshot 2025-01-29 at 3.34.14 PM.png

  1. You can find this by right clicking on the add to cart button and clicking "Inspect"
  2. Once you find that, you'll want to search your theme files until you find this snippet of code. For this example I searched for `product-info__buy-buttons` which led me to `buy-buttons.liquid`
  3. In this file I added:
<input id="your-name" type="hidden" name="properties[_Your name]" value="{{ product.selected_or_first_available_variant.metafields.custom.metafield_key">

 

Change the "name" to something like: name="properties[_Drawer Number]"

Change the "value" to value ="{{ product.selected_or_first_available_variant.metafields.custom.drawer_number }}"

This is only about halfway complete— the challenge is going to be updating the value when the variant changes, that will require some Javascript, and is pretty specific to the theme. This is where chat GPT will be your best friend. Most themes have some built in events, and these events are usually in the theme documentation. If you can locate the variantChange event documentation, give that to chat GPT and ask it to "Update the value each time the variant is changed" and you should be good!

I know it might not be the answer you were looking for, but I hope it helps!
 

Sean
-
PATANE, Shopify Experts