Adding Customer Metafield to Order

Solved
PinkProBeauty
New Member
6 0 0

Is it possible to add a custom customer metafield value to the order using Flow? Is there another way to achieve this? 

 

Our CRM has to communicate with Shopify using existing customer identifiers. 

 

Thank you in advance. 

Accepted Solution (1)
Brett_Helium
Shopify Partner
144 32 51

This is an accepted solution.

@PinkProBeauty, to add a value to the order metafield you would want to use the following liquid code, making sure to use the appropriate namespace and key corresponding to your customer metafield.

{%- for metafields_item in customer.metafields -%}
  {%- if metafields_item.namespace == "NAMESPACE"
    and metafields_item.key == "KEY" -%}    
      {{metafields_item.value}}
  {%- endif -%}
{%- endfor -%}

  
Also make sure to use an appropriate metafield type for the data you are trying to add.

Here's an example screenshot: https://share.heliumdev.com/7KuW9YA4

Brett | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (330+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (250+ reviews)

View solution in original post

Replies 13 (13)
paul_n
Shopify Staff
Shopify Staff
603 97 154

It's possible to check a customer metafield value when an order is placed, yes. Where would you need to insert the value?

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
PinkProBeauty
New Member
6 0 0

Thank you for replying Paul! 

 

I need the value of the custom customer metafield to be inserted on the order itself. 

 

Basically I need my CRM to recognize the Shopify order came from that specific customer that has a pre assigned customer number by the CRM. We uploaded all of those customer numbers as custom metafields to the customer profilles, I just need whenever an order is created for that customer metafield to attach to the order so whenever it is exported, it will be visible on the spreadsheet to use as the common identifier. 

paul_n
Shopify Staff
Shopify Staff
603 97 154

So I don't know what fields your CRM imports. Also, you may run into an issue where the CRM imports the order before the order is updated. Currently, the three places you can add additional info to an order, via Flow, are the order note, order tags, or order metafields.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
PinkProBeauty
New Member
6 0 0

We have to manually set the schedule for imports. I found the update order metafields, but I can't seem to get it to add the customer metafield. Could you assist further with this? I really appreciate your assistance. 

Brett_Helium
Shopify Partner
144 32 51

This is an accepted solution.

@PinkProBeauty, to add a value to the order metafield you would want to use the following liquid code, making sure to use the appropriate namespace and key corresponding to your customer metafield.

{%- for metafields_item in customer.metafields -%}
  {%- if metafields_item.namespace == "NAMESPACE"
    and metafields_item.key == "KEY" -%}    
      {{metafields_item.value}}
  {%- endif -%}
{%- endfor -%}

  
Also make sure to use an appropriate metafield type for the data you are trying to add.

Here's an example screenshot: https://share.heliumdev.com/7KuW9YA4

Brett | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (330+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (250+ reviews)
PinkProBeauty
New Member
6 0 0

This worked like MAGIC! 

Thank you so much. We're also Helium customers as well 🙂 

Brett_Helium
Shopify Partner
144 32 51

Using Liquid in Shopify Flow can definitely be a bit tricky, but I'm glad to hear that worked for you!

And thanks for using our apps, we're always glad to hear that 😁

Brett | Helium
Helium builds apps that thousands of merchants depend on:
- Customer Fields ✪✪✪✪✪ (330+ reviews)
- Meteor Mega Menu ✪✪✪✪✪ (250+ reviews)
gr_trading
Shopify Partner
1396 130 151

Hi @PinkProBeauty 

 

You can use the below code to implement the same

 

{% if customer.metafields.register.company != blank %}
<input type="text" name="attributes[crm_attribute]" form="cart" value="{{customer.metafields.register.company}}" />
{% endif %}

 

customer.metafields.register.company is metafield name replace it with your value.

 

Hope this will help...

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
paul_n
Shopify Staff
Shopify Staff
603 97 154

This is asked for Shopify Flow. I think your solution here is to customize the checkout liquid.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
gr_trading
Shopify Partner
1396 130 151

no this is a cart page modification.

 

Please refer the below article for more details

 

https://shopify.dev/docs/themes/architecture/templates/cart

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
PinkProBeauty
New Member
6 0 0

Thank you! I will have IT try this method momentarily. 

PinkProBeauty
New Member
6 0 0

Where exactly do I need to put this code? It's giving me an error when I add it to the cart.json 

gr_trading
Shopify Partner
1396 130 151

main-cart-footer.liquid

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee