Last active
February 8, 2024 10:50
-
-
Save mntolia/7c73b4de3f99f2d3b11a4d275a60fe2f to your computer and use it in GitHub Desktop.
This file contains 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
//Constants | |
const inventory_sheet = "inventory" | |
const item_id_column = 1 | |
const quantity_column = 3 | |
const price_column = 4 | |
const regular_price_column = 5 | |
const consumer_key = "s3cr3t" | |
const consumer_secret = "s3cr3t" | |
const order_id_column = 1 | |
const status_column = 8 | |
const ordered_items_column = 4 | |
const variation_id_column = 6 | |
function onEdit(e) { | |
var sheet = e.source.getActiveSheet() | |
sheet_name = sheet.getName() | |
//Updating Inventory | |
var range = e.range | |
var item_id = sheet.getRange(range.getRow(), item_id_column).getValue() | |
//Updating Stock Quantity | |
if (sheet_name == "inventory") { | |
if (e.range.getColumn() == quantity_column) { | |
var request_body = { | |
"stock_quantity": e.value | |
} | |
} | |
//Updating Sale Price | |
else if (e.range.getColumn() == price_column) { | |
var request_body = { | |
"sale_price": e.value | |
} | |
} | |
//Updating Regular Price | |
else if (e.range.getColumn() == regular_price_column) { | |
var request_body = { | |
"price": e.value, | |
"regular_price": e.value | |
} | |
} | |
var options = { | |
'method': 'put', | |
'contentType': 'application/json', | |
'payload': JSON.stringify(request_body) | |
} | |
UrlFetchApp.fetch("https://my-secret-woocommerce-site" + item_id + "?consumer_key=" + consumer_key + "&consumer_secret=" + consumer_secret, options) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment