Created
July 19, 2019 22:07
-
-
Save ashokrane/a2174359d3492653c6e36dd9c46e549a to your computer and use it in GitHub Desktop.
Google apps script for integration of WooCommece orders to Google sheets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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_created = myData.date_created; | |
var order_status = myData.status; | |
var product_name = myData.line_items[0].name; | |
var product_qty = myData.line_items[0].quantity; | |
var product_total = myData.line_items[0].total; | |
var order_total = myData.total; | |
var billing_email = myData.billing.email; | |
var billing_first_name = myData.billing.first_name; | |
var billing_last_name = myData.billing.last_name; | |
var payment_method = myData.payment_method_title; | |
var shipping_method = myData.shipping_lines[0].method_title; | |
var shipping_total = myData.shipping_lines[0].total; | |
var timestamp = new Date(); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow([timestamp,order_number,order_created,order_status,product_name,product_qty,product_total,order_total,billing_email,billing_first_name,billing_last_name,payment_method,shipping_method,shipping_total]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment