【发布时间】:2021-06-10 07:43:18
【问题描述】:
我正在使用下面的脚本通过 webhook 将 WooCommerce 订单导入 Google 表格。 数据按预期导入,但仅显示每个订单的第一个产品。我将如何修改脚本以包含每个订单的多个产品名称和产品数量?*****
//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 first_name = myData.billing.first_name;
var last_name = myData.billing.last_name;
var address = myData.billing.address_1;
var town = myData.billing.city;
var postcode = myData.billing.postcode;
var product_name = myData.line_items[0].name;
var product_qty = myData.line_items[0].quantity;
var notes = myData.customer_note;
var timestamp = new Date();
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([timestamp, order_number, first_name, last_name, address, town, postcode, product_name, product_qty, notes]);
}
谢谢, 本
【问题讨论】:
-
看你是如何导入
e.postData.contents中的数据的?
标签: google-sheets woocommerce webhooks google-sheets-api