Custom Line Item Properties and Cart Attributes

Pass custom data to the cart and beyond at the product or order level.

Line item properties and cart attributes are Shopify features that allow you to apply data to an order that can be accessed in the cart, checkout and order in Shopify to be used in the Shopify backend & fulfilment.  

Custom line item properties are applied to individual line items within the cart/order

Custom cart attributes are applied to the entire cart/order 

This article walks you through: 

Using line item properties and cart attributes with Nyla

In Nyla, line item properties and cart attributes allow you to create powerful features that enable custom information to be added to the cart and to customer orders. 

Nyla’s Line Item Properties and Cart Attributes feature enables you to:

  • Apply custom line item properties and cart attributes using: 
    • Forms
    • Link actions
    • Automated rules to automatically based on properties
  • Choose whether custom line item properties and cart attributes can be shown in checkout or not
  • Use Custom Line Items and Cart Attributes as properties on your Nyla site

Use cases: There are many potential applications, but some common use cases include: 

  • Gift Notes
  • Gift Wrapping
  • Customised messaging on products (e.g personalization)
  • Passing information from Shopify metafields through to the order details for use in fulfillment (for example, if an item is pre-order or not)

Creating Line Item Properties or Cart Attributes


Using a line item property or cart attribute in a link action, form or rule within the Line Item Properties and Cart Attributes app (Apps > Shopify > Line Items) will add it to your site,  e.g by creating the method to add the line item property or cart attribute, you are also adding it to your site. 

When creating your line item property or cart attribute, you can only use the following characters:

  • Numbers or letters
  • Underscore

Eg: gift_notes, gift-name, _is_gift

Adding Line Item Properties or Cart Attributes to your site


Line items and cart attributes can be added via a link action, using form or by creating rules within the Line Item Properties and Cart Attributes app (Apps > Shopify > Line Items).


Adding via Link Actions: 

  • Use the link actions defined here
  • When you add the link actions, a field will appear requiring for you to add the property name. Once you'd added the link action, this line item property will be available as a property on the site. 
  • You can only add line item properties using link actions on the cart. If you want to do it on the PDP, you should use the form method. 

Forms

It's possible to add custom line item properties and cart attributes using forms. 

When adding custom line item properties using this method, the line item property name will be set as whatever you put as input handle. 

Custom line item properties: You can add a custom line item using a form input with add to cart inside of source: product, source: nosto and within grid and slide layouts in source: collection. These entities are wrapped in a form so you can add any form input to them and the line item property will be submitted when add to cart button is clicked. 

Custom cart attributes: Add a form with any form input(s) to the cart with the ADD_CART_ATTRIBUTES submit action. The data will be submitted with the form submit button. 

In this example, this input added within a source: product will add a line item property of "engraving" once the product is added to the cart. 

Rules via properties

You can apply custom line item properties and cart attributes automatically via rules that you set in the Shopify app. Go to Apps > Shopify > Line items

In the example below, a line item property with the name pre-order is applied to a product if the custom metafield (added via the metafields app) preorder is equal to true. When it is applied, the line item property has a value of "Ships" plus then the value that the product has in the custom metafield pre_order date. 

This is then used by this Nyla customer to display a preorder date (using the properties.Pre-order property generated via this rule) on the product in the cart and checkout for any product that has been set by the customer as a preorder in Shopify. 

Things to note with applying line item properties and cart attributes using rules: 

  • Line item properties run when an add to cart event happens. 
  • Cart attribute rules can only access global properties.

Displaying custom line item properties and cart attributes as properties


To display your line items as properties within the cart or source product (in the case of line item properties), you can use the following:

{{ properties.[thepropertyname] }} if you are inside a line item with Source Cart Items

  • {{ properties.isnothiddenincheckout }}
  • Displaying custom line item properties in checkout


    In order to decide whether it is hidden or shown at checkout, you should add an underscore before the name of the attribute.

    Note that cart attributes don’t appear during checkout, so this rule is only for line item attributes.