Re: Add number of customer orders in past 3 months to order note

Add number of customer orders in past 3 months to order note

GenOnDev
Tourist
3 1 1

Good morning,

I have a requirement of displaying the number of orders by a customer in a specific timeframe e.g. last 3 months on the order invoice. It doesn't look like order printer has the customer.orders object to work with so I was looking for a workaround using Shopify Flow.

If I can get this number into the order note, I should be able to pull it into the invoice. I've tried the following code using the modify order note action:

 

{% for order in customer.orders %}
  Date: {{ order.created_at }} <br>
{% endfor %}

 

However, when I save the flow and then click "Preview Workflow" I get an error saying "Your workflow can't be previewed. Fix any errors and try again." 

 
Also, not sure how I would implement a specific timeframe and count the number of orders rather than just displaying dates for all orders?

 

Any assistance would be appreciated!

Reply 1 (1)

pvoulg
Shopify Partner
178 26 62

Hi @GenOnDev

I'm pretty sure you cannot do that using Flow either. While liquid works in Flow, it only does so as long as you work with the available template variables, so your code won't run (which is causing your error message). I don't believe there is a way to list a customer's previous orders from an Order created trigger (you can only get the Customer order count, which is not helpful in your situation).

If there were such a way, you could probably do the second part of your query by pushing all past orders in an array with a timestamp for each, then assign a variable with the current date, minus your timeframe limit, and from there figure out how many items in your array are larger than your variable—which would be the number of orders within that timeframe.

You might be able to pull that kind of information using Zapier, or another 3rd-party connector. You could probably use a webhook when an order is created, then pull the customer ID, search the store for orders with that customer ID (since the customer.json doesn't supply that information by itself), and you could maybe sort of kinda get what you need(?). I'm really not sure Zapier's API connection allows for everything I mentioned, but it might be worth a shot. 

If anything else comes to mind I'll drop you another reply here.

Panos Voulgaris
Creative director / Partner @ MALVI
Founder @ function( )