How can I add inventory levels to Custom Meta Field?

I have two store locations with different inventory levels. When the inventory changes in a speciffic location I want to update a speciffic custom meta field. So location “A” would update “custom.a”

I have tried using {{productVariant.inventoryItem.inventoryLevels.available}} and I have got success message but nothing shows up in the custom meta field.

I can also see that available is depreciated:
“The quantity of inventory items that are available at the inventory level’s associated location. Use the quantities field instead and specify available for names. Example: quantities(names:[“available”]){name quantity}.”

But I havent been able to get quantities to work. A point in the right direction would be great.

My thanks in advance.

1 Like

I have tried using {{productVariant.inventoryItem.inventoryLevels.available}} and I have got success message but nothing shows up in the custom meta field

You are close, but inventoryLevels is a list. So you need to loop over it. Probably what I would do in this scenario is:

  • product variant inv changed trigger
  • for each variant / inventoryItem / inventoryLevel
    • if level / location / name = X
      • update metafield (using the the inventoryLevel_item.available from the loop)
    • if level / location / name = y
      • update metafield (same)

Hi Paul_n, sorry to revive an old thread, but it’s the closest to my issue after a lot of searching. I’m using the same trigger as OP; however, in the environment values, there is no “quantities” option for me to actually get the quantity for the variant whose inventory level changed. Is there a reason why it’s not visible as a variable option?

It’s now under deprecated.