• Instructions to Ask a Question

    Click on the "Ask a Question" button and select the application for which you would like to ask questions.

    We have 5 different products namely - Pabbly Connect, Pabbly Subscription Billing, Pabbly Email Marketing, Pabbly Form Builder, Pabbly Email Verification.

    The turnaround time is 24 hrs (Business Hours - 10.00 AM to 6.00 PM IST, Except Saturday and Sunday). So your kind patience will be highly appreciated!

    🚀🚀Exclusive Discount Offer

    Just in case you're looking for any ongoing offers on Pabbly, you can check the one-time offers listed below. You just need to pay once and use the application forever -
     

    🔥 Pabbly Connect One Time Plan for $249 (🏆Lifetime Access) -  View offer 

    🔥 Pabbly Subscription Billing One Time Plan for $249 (🏆Lifetime Access) - View offer

Calculate price of WooCommerce line item

davidw

Member
I want to create invoices in Invoice Ninja from new WooCommerce orders. Here is my workflow outline:

1. Trigger: New order in WooCommerce
2. Line itemizer to get the items in the order
3. Create an invoice in Invoice Ninja

The problem is that WooCommerce doesn't include the line item price, it only includes the subtotal. The below order includes the following:

Web Development 2x$50 = $100
Website migration 1x$75 = $75

CleanShot 2023-11-05 at 00.52.58.png


Invoice Ninja needs the rate and quantity of each line item, i.e. rate for Web Development is $50. It's easy to find this value, just take the subtotal and divide by the quantity. But how do I do this with Pabbly please?

I need the output to be 50,75.

Thank you
 

ArshilAhmad

Moderator
Staff member
Hi @david466,

Please try adding this JavaScript code to your workflow using Code by Pabbly. This should give you the desired result.
JavaScript:
const subtotals = [100, 75]; // Array of subtotal prices
const quantities = [2, 1];  // Array of quantities

const result = subtotals.map((subtotal, index) => subtotal / quantities[index]);

const resultString = result.join(', ');

console.log(resultString); // Output the results as a comma-separated string

1699120623923.png



 

davidw

Member
Thank you, exactly what I needed. Is it best practice to simply assign the result to the output variable? e.g.

JavaScript:
const result = subtotals.map((subtotal, index) => subtotal / quantities[index]);

const resultString = result.join(', ');

output = resultString;
 

ArshilAhmad

Moderator
Staff member
The code I shared above was generated using ChatGPT, so unfortunately, I won't be able to assist you with coding-related queries as it's beyond our scope of expertise.
 
Top