Best answer

Question about line items where more than one of the same item has been purchased

  • 27 July 2021
  • 5 replies
  • 161 views

Hi all,

I am using zapier to output WooCommerce orders into a google spreadsheet, but I’m looking for a way to separate quantities into individual line item entries.  So far I have been using the line item feature to separate different products, but I want to go one step further so that each item has its own line.

So for example, an order that looks like this

SKU ITEM NAME FIRST NAME LAST NAME EMAIL PHONE ORDER DATE ORDER ID QUANTITY
PS03 002 - The King Jonny Rockets me@xyz.ca 1234567789 Jan 1, 2021 14570 3

 

Would end up being outputted onto my google sheet like so

SKU ITEM NAME FIRST NAME LAST NAME EMAIL PHONE ORDER DATE ORDER ID QUANTITY
PS03 002 - The King Jonny Rockets me@xyz.ca 1234567789 Jan 1, 2021 14570 1
PS03 002 - The King Jonny Rockets me@xyz.ca 1234567789 Jan 1, 2021 14570 1
PS03 002 - The King Jonny Rockets me@xyz.ca 1234567789 Jan 1, 2021 14570 1

 

Is there a solution to this?  I have been searching through the forums but my issue as always is not being able to explain the problem well, so hopefully this makes sense to whoever reads it!

 

Thanks in advance,

Luke

icon

Best answer by Troy Tessalone 27 July 2021, 04:28

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.

5 replies

Userlevel 7
Badge +14

Hi @LukeSummers 

Try using the Looping app: https://zapier.com/apps/looping/integrations

Userlevel 7
Badge +12

Hi @LukeSummers 

This is a bit advanced but since Google Sheets’ Create New Line Items action supports line items, it is significantly more efficient to process your line items with a code step and then pass them forward all at once.. Something similar to this should do the trick. 

 

var finalOutputLines = [];

let qtys = inputData.qtys.split(",");
let items = inputData.items.split(",");

var i=0;
qtys.forEach(qty => {
while (qty>=1) {
finalOutputLines.push({qty: 1, item: items[i]})
qty--;
}
i++
})

return {finalOutputLines}

 

To add a little context, the products that I am exporting from WooCommerce are entries for an art raffle, and each line will be mail merged onto a ticket.  Therefore, if someone purchases 3 tickets for the same item, I would need three separate lines for each entry.

Thanks!

Luke

Thank you for your response @Troy Tessalone, unfortunately after reading the documentation and trying unsuccessfully I’m really not sure how to use the looper to duplicate rows based on the quantity of item.  

Would you mind elaborating on how the looper function should be used?  Would I use text, number or line item, and how do I set the number of duplicate items to be based on the entry to the quantity field.

Thanks for your patience and assistance.

Luke

 

Userlevel 7
Badge +14

@LukeSummers 

Try these Zap steps…

  1. Trigger: WooCommerce - Line Item in Order
  2. Action: Looping - Numbers (you can map the Qty value to the Loop Iteration Counter End)
  3. Action: GSheets - Create Row (set a static value of 1 for the Qty)