Force quantity column header on sales invoice to always show as “Qty”

I seem to have got it working. I did the following:

  1. At the top of the table, create variables to hold values for the column index (a number) and the unit (a string): {% assign myUnitIndex = 0 %}{% assign myUnit = "" %}
  2. In the column heading, remove {{ column.label }} and replace with {% if column.label == "M" or column.label == "L" or column.label == "Hours" %}{{ "Qty" }}{% assign myUnit = column.label %}{% assign myUnitIndex = forloop.index %}{% else %}{{ column.label }}{% endif %}
  3. In the cell text, after {{ cell.text | newline_to_br }} add the following: {% if forloop.index == myUnitIndex %}{{ " " }}{{ myUnit | downcase }}{% endif %}

Step 2 checks to see if the column header matches any of my units, so I’ll need to update this if I create any new units. If there’s a match, it places the text “Qty” in the column header, assigns the matching unit to the variable myUnit, and assigns the column index to the variable myUnitIndex.

Step 3 checks to see if the column index for the cell matches the column index saved to the variable in step 2. If it does (ie if it’s in the quantity column), it adds a space followed by the unit converted to lowercase. This hopefully avoids any problems arising from item custom fields or anything else that might change the number of columns or column order.

So, it’s a slightly cumbersome workaround, but after initial tests the result seems to be exactly what I wanted.