Best answer

WooCommerce: get order from a specific variation ID

  • 5 September 2022
  • 4 replies
  • 352 views

Userlevel 1
Badge +1

Hi

I’ve got my weekly summary task email from zapier and noticed that one specific Zap (runs once per month) used up to 295 tasks.
Which is a lot.

So I’m here wondering if any of you have a similar use case and how you guys limit the actions.

Use case:
* Woocommerce webshop
* I need all orders that ordered a specifik Product variation. 

I’m using the woocommerce API with the built in filter on product ID:

/wp-json/wc/v3/orders?status=completed,processing&after=2021-07-30T18:46:32&per_page=50&product=2111&order=desc

There’s no built in filter with the API to pass through a variation ID. So I’m forced to use a loop with a condition:

 

=> Which is the reason of the many actions. If the API call returns 50 lines; each line can contain more than one product/variation which need to be filtered.

Any suggestions to get the number of actions down? (I can limit the amount with the date, but currently I’m only fetching the first 50 returned lines anyway)

 

Thanks in advance for having a look at it.

icon

Best answer by Danvers 5 September 2022, 17:24

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 7
Badge +12

Hi @Hexmans!

My understanding of the issue is that you need the Zap to run only for a specific product variation ID, but the as the production variations are in a line item field, you need to run a loop and filter step for each product variation in the order, is that right?

If so, I think I have a solution:

Add a Formatter by Zapier step into the Zap and choose Utilities > Line-item to text. This will take the Product variation field and convert it from line items to one long string of text with a comma after each variation. 

 

In the filter step, set it up so that the filter is looking for the Product variation ID you want to filter for followed by a comma. The comma will stop the filter from stopping the Zap if you have a number like 345 and you’re trying to filter for 123456. 

 

Set up that way, you would have one task to convert the line items and 1 task to search the string. Would that work with the data that you have?

Userlevel 1
Badge +1

Hi @Hexmans!

My understanding of the issue is that you need the Zap to run only for a specific product variation ID, but the as the production variations are in a line item field, you need to run a loop and filter step for each product variation in the order, is that right?

If so, I think I have a solution:

Add a Formatter by Zapier step into the Zap and choose Utilities > Line-item to text. This will take the Product variation field and convert it from line items to one long string of text with a comma after each variation. 

 

In the filter step, set it up so that the filter is looking for the Product variation ID you want to filter for followed by a comma. The comma will stop the filter from stopping the Zap if you have a number like 345 and you’re trying to filter for 123456. 

 

Set up that way, you would have one task to convert the line items and 1 task to search the string. Would that work with the data that you have?

 

Thanks for your response.
So I’m testing that out right now. But I’m a bit confused
The API call returns

Order A with one or more product/variation

Order B with one or more product/variation

Order C with one or more product/variation

I still have to loop order A, B and C to then convert each line variation ID into text and filter, right?

I need all the orders that have bought a specific variation ID

Userlevel 7
Badge +12

Hi @Hexmans!

You wouldn’t need to loop the line items before convert them into text. Converting the line items to text will turn them into one regular text field, if you set up the filter step to look at that text field (as opposed to the original live items) the filter can look at that one field to find any mention of ‘variation D’. 

I hope that clears things up, let us know if you have any other questions!

Userlevel 7
Badge +12

Hi @Hexmans, were you able to give the Formatter line-item to text action a go? Let us know if it worked or if you still need some help!