Update Order Metafield \n error. For value: "330\n"

Topic summary

A user is encountering an error when attempting to update a Shopify order metafield with a calculated total volume value. The error message indicates: “Value must be an integer” for value “330\n”, suggesting a newline character (\n) is being appended to the number.

Code Context:

  • The user’s Liquid template calculates total_volume by iterating through order line items
  • It multiplies each variant’s volume by quantity and sums the results
  • Despite using hyphens in Liquid tags to strip whitespace, one trailing newline persists

Proposed Solution:
Another user suggests modifying the output tag from {{total_volume}} to {{- total_volume -}} (adding hyphens on both sides) to remove the trailing whitespace/newline character that’s preventing the value from being accepted as a valid integer by the metafield.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

I have used the hyphens in each to get rid of the majority of them. For some reason there is one at the end that still does not go away. Exception: Got error updating metafield: “Value must be an integer.” For value: “330\n”, Type: number_integer.

{%- assign total_volume = 0 -%}
{%- for lineItems_item in order.lineItems -%}
{%- assign product_volume = lineItems_item.variant.variantVolume.value -%}
{%- assign item_volume = product_volume | times: lineItems_item.currentQuantity -%}
{%- assign total_volume = total_volume | plus: item_volume -%}
{%- endfor -%}
{{total_volume}}

{{- total_volume -}}

1 Like