Skip to main content

How to add metafields in cartLineItem

Introduction

​ This guide will show you how to get metafields in the cart. ​

note

Make sure you use the exact keys and namespaces for the metafields.

Steps​

  1. Create a file functions.js in the packages/your-package-name/ directory.
  2. Add the following code to the functions.js file: ​
import { fieldsHelper } from "@appmaker-xyz/shopify";

export function addProducFieldstToCartLineItems() {
fieldsHelper.addFieldsToCartLineItem({
fields: {
variant: {
product: {
// here you can add any product field
custom_products_list: {
__aliasFor: "metafield",
__args: {
key: "products_list", // here you add the key of the metafield
namespace: "custom", // here you add the namespace of the metafield
},
value: true,
},
},
},
},
});
}

​ 3. Add the following code to the index.js file: ​

import { addProducFieldstToCartLineItems } from "./functions";

addProducFieldstToCartLineItems();