Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Pushing Woocommerce orders to Google Sheets

I have setup a woocommerce website, used for delivery of meals from different restaurants in my area. I have tried to setup an automatic transfer of the order data from the json file straight to a Google sheet our drivers use, but I have found myself encountering errors in Google Script everytime woo's webhook fires, and not being able to detect the issue.

Here is my google script code

//this is a function that fires when the webapp receives a GET request
function doGet(e) {
  return HtmlService.createHtmlOutput("request received");
}

//this is a function that fires when the webapp receives a POST request
function doPost(e) {
  var myData = JSON.parse([e.postData.contents]);
  var order_number = myData.number;
  var order_address = myData.billing.address_1;
  var item = ""
  var url = "https://fivestars-delivery.com/mon-compte//driver-dashboard/?orderid=" + order_number;

  for (var i = 0; i < myData.line_items.length(); ++i) {
    item += myData.line_items[i].product_id + "\n"
    total += parseInt(myData.line_items[i].total)
  }

  var fees = ""
  // var feesTotal = 0

  for (var i = 0; i < myData.fee_lines.length(); ++i) {
    // convertir en entier
    // feesTotal += parseInt(myData.fee_lines[i].total)
    fees += myData.fee_lines[i].amount + " " + myData.fee_lines[i].name + " - " + myData.fee_lines[i].total + "\n"
  }

  var discount = myData.discount_total
  // nom client
  var nomClient = myData.first_name + " " + myData.last_name
  var order_total = myData.total;
  var payment_method = myData.payment_method_title;
  var phone = myData.billing.phone

  var note = myData.billing.address_2 + "\n" + myData.customer_note

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.appendRow([order_number, " ", " ", " ",order_address, " ", "Attente d'envoi",url, order_total, payment_method, nomClient, phone, note, item + fees + discount, ]);
}

-I set up a WooCommerce API and webhook using the api's secret key

-Entered my web application's URL as delivery URL in the webhook

I cannot find out what is wrong and none of the situations I found online have found no help so far.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The variable total is never created, but it is used within the for loop.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!