• Instructions to Ask a Question

    For any assistance, please click the "Ask a Question" button and select the Pabbly product for which you require support.

    We offer seven comprehensive applications designed to help you efficiently manage and grow your business:

    Our support team endeavors to respond within 24 business hours (Monday to Friday, 10:00 AM to 6:00 PM IST). We appreciate your understanding and patience.

    🚀 Exclusive Lifetime Offers 🚀

    We invite you to take advantage of our special one-time payment plans, providing lifetime access to select applications:

    • 🔥 Pabbly Connect — Lifetime Access for $249View Offer
    • 🔥 Pabbly Subscription Billing — Lifetime Access for $249View Offer
    • 🔥 Pabbly Chatflow — Lifetime Access for $249View Offer

    Make a one-time investment and enjoy the advantages of robust business management tools for years to come.

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