skip to Main Content

While working on a "Line Items" script, I want to display product name as part of a UI message. I can get the variant name using line_item.variant.title and product object using ‘line_item.variant.product` but how do I get the product title?

Any help will be much appreciated.

Thanks.

2

Answers


  1. You don’t have access to the title of the product by default, you can refer the docs here: https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#product

    But what you can do is pass a custom property to the product when you are adding it to the cart with the product title and refer to that property in the Shopify Scripts code.

    <input name="properties[__product-title]" value="{{ product.title }}" />

    And in the script:

    Input.cart.line_items.each do |line_item|
      next if line_item.properties.empty?
      productTitle = line_item.properties['__product-title']
      // Rest of the logic
    end
    
    Login or Signup to reply.
  2. You can access title’s from the variant by using

    https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#variant

    line_item.variant.title

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search