Variant Metafields & Order Printer App

Cameron_Shaw
Tourist
5 0 2

Hi All,

I'm doing some work for a client, and working on customizing the template for the Order Printer app to include some additional information. 

They use metafields on the variant object to include this info, and the following code works fine on the cart page to display the information (inside the cart line item loop):

{% if item.variant.metafields.variant-fields.variant_skus != blank %}
  <span>Includes: {{ item.variant.metafields.variant-fields.variant_skus }}</span>
{% endif %}

However, the same code in the order printer template file doesn't produce any output. 

Thanks in advance,

Cameron

Replies 3 (3)
Jordy_D
Shopify Partner
118 0 51

Hi Cameron, 

Order printer doesn't have access to metafields, of any kind.

Unfortunately.

★Shopify tweaker★
Cameron_Shaw
Tourist
5 0 2

Hi Jordy,

Thanks for your response. 

Sadly this does appear to be the case, though I haven't found any documentation to this effect.

 

Ognjen_Knaus
Shopify Partner
5 0 1

Here's a workaround. As usual, in Shopify you need to get creative

 

You can add cart attribute and then print it on the Print order.

So what I came up with is to a hidden field that will capture the attribute, and we will send metafield value to that att then print it on Print Order.
_{{item.id}}  is there in the attribute  name so we can have a dynamic attribute cause it needs to be unique to the cart item printed.

Step 1:
On the cart page, add this right below, for example, cart item title (if you wanna see it, remove "hidden"):

 

 

 

<input id="recipe" name="attributes[recipe_{{item.id}}]"  value="{{item.variant.metafields.settings.variant_recipe}}" hidden></input>

 

 

 


Step 2:
Then on the print order template use this right below line item Title (where you see Product variant showing in the order):

 

 

 

{% capture lineItemID %}{{ line_item.variant.id }}{% endcapture %}


{% for a in attributes %}
{% assign a_internal = a.first | slice: 0 %}
{% if a.first contains "recipe" and a.first contains lineItemID and a.last != blank %}
<p>Recipe: {{ a.last }}</p>
{% endif %}
{% endfor %}

 

 

 

First we capture the cart item id, then loop through all the attributes, break name and value (those are first and last you see in the code) to get the attribute name, and show only the one with the "recipe" in the name and with current line item id.

We print the value only of that att we need.

 

Ognjen_Knaus_0-1637764939621.png

 



Ognjen_Knaus_1-1637764771979.png

 

 

 

Get in touch for more help.
beocode.com
Every pixel counts!