Updating Google Sheet with WooCommerce Order - google-apps-script

I need to be able to automatically update a google sheet file every time an order is placed through WooCommerce.
I've found the solution below, but using this each individual item ordered is listed as a new row. I'd like the order to be grouped under the order number and the item quantities separated into appropriate columns instead.
https://www.tychesoftwares.com/export-woocommerce-orders-to-google-sheets-in-realtime/
Below is a Google Sheet we are manually updating at present to show you what i mean.
Example
Is there a way to send the WooCommerce orders directly through to Google Sheets in this format?
Thanks so much in advance for any advice!

Yes it looks possible.
I know nothing about WooCommerce, but I believe you can sort out the received data in any way you want.
Look, the last line in their script appends the received data as a new row:
sheet.appendRow([timestamp,order_number,order_created,order_status]);
As far as I can see, the data contains the four elements:
timestamp
order_number
order_created
orders_status
Instead, you can put these elements into any cell on your table. Something like this, for example:
var ss = Spreadsheet.GetActiveSheet();
ss.getRange('A10').setValue(timestamp); // timestamp goes to A10
ss.getRange('B20').setValue(order_number); // order_number goes to B20
ss.getRange('C30').setValue(order_created + order_status); // created + status go to C30
The same way you can add any of these elements to some existing value in some cell, etc. For example:
var old_value = ss.getRange('A2').getValue(); // get value from the cell A2
var new_value = old_value + order_number; // add with order_number
ss.getRange('A2').setValue(new_value); // put the sum back into the cell A2
The main problem is up to you. You have to figure out:
what exactly the elements you're receiving (number, names)
how exactly you want to sort them out (what to add to what... what to put where... etc)
I can't understand it from the example picture.
Here is some reference documentation on Apps Script:
Main Page - Introducing Apps Script.
Sheets Guide - Introduction to Sheets with Apps Script.
Sheets Reference - Where you will find all the details of everything you can do with Sheets in Apps Script.
Remove Duplicate Rows - A good small tutorial that will teach you the basics of Sheets and Ranges and how to manipulate them.

To export all my WooCommerce orders on a scheduled basis, I used a ready-made solution.
I used a WooCommerce API and JSON client. It worked smoothly: I got the WooCommerce API, and the JSON client was implemented in the tool already.
You just need to choose endpoint in the JSON client to get the required data. I exported all orders once a month, so I used the base URL http:// mydomain /wp-json/wc/v3/orders and my endpoint was orders.
You can check this article to understand better how it works for your purpose.
And here is WooCommerce API documentation.
I assume that setting up an export through the Apps Script is more flexible (and based on the answer above, it's working indeed), but I'm not a code guy. So I searched for an easier solution, and the API + JSON client helped.
Hope you'll find it helpful.

I would like to suggest using WooCommerce Google Sheet Plugin

Related

Remove characters from a cell with imported API data in Google Sheets - or format api import

I'll start by saying that my knowledge on using APIs is extremely limited. I'm impressed I've gotten as far as I have on this.
I've created a workbook in Google Sheets with imported data from the iexcloud API, which I'm using for data on stocks.
The requests have a cell reference in them so they update whenever a different symbol is selected.
So far, everything I've needed to request from it has the option to format as csv, so I can get cells with just the values.
However, this last thing I want doesn't have that option, so the whole response is wrapped in ["" ].
That really messes up what I need it for.
Here's an example
["PSA" CCI SHO ACC]
with each symbol being in its own cell.
I'm using the Peer Groups request.
A sample request:
> https://sandbox.iexapis.com/stable/stock/aapl/peers?token=Tsk_2b4c7c6fd98542f6a99f904cb7a3e721
Using Find and Replace doesn't work. I'm assuming because it's imported.
I need to use the cells with those symbols: PSA, CCI, SHO, ACC to reference in another request.
I recreated this in another Google Sheet that you can edit. The section in question in highlighted in blue
https://docs.google.com/spreadsheets/d/1BQ6FBD0S2YkDtDGZGIkDmQoKrQT4VmVDjuNsgV4mrXM/edit?usp=sharing
So I'm wondering if there's a way to have [ " ] automatically removed from any cells in that row, or if I copy and paste the values only, to have the values updated when the original cells are updated with new symbols (since I can have those characters removed in that row)
Or if there's a way I can format the response in sheets.
Any ideas?
I believe your goal as follows.
You want to achieve from ["CCI" SBAC CTL TDS RCI RCI-A-CT DTEGY] to CCI SBAC CTL TDS RCI RCI-A-CT DTEGY using the built-in functions of Google Spreadsheet.
Modified formula:
=ARRAYFORMULA(REGEXREPLACE(IMPORTDATA("https://cloud.iexapis.com/stable/stock/"&B3&"/peers?format=psv&token=###"),"[\[\]""]",""))
In this modified formula, [, ] and " are removed using REGEXREPLACE.
Please replace ### with your token at the above formula.
Result:
In this result, the values retrieved with =IMPORTDATA("https://cloud.iexapis.com/stable/stock/"&B3&"/peers?format=psv&token=###") are used. So the formula of cell "C9" is =ARRAYFORMULA(REGEXREPLACE(C6:I6,"[\[\]""]","")). But in this case, above modified formula can be used.
Note:
In this answer, I removed your token because I thought that it is your personal information.
Reference:
REGEXREPLACE

Is there a way to have google form responses to record in sheets depending on what section of the form is filled out?

I made a form with multiple conditional paths and my response sheet is ungodly I could really use some help.
The way I set up the form has a total of 19 sections
Location Dropdown (we have 3)> Machine dropdown (a total of 15)> A Machine Specific measurement section and Submit.
I split the Measurements sections by machine because, I was hoping I could have each section record numbers into separate sheets. This way I could keep each Machine's data on its own google sheet.
So logically I am trying to get MachineX measurements to record sheet X but, Get Machine Y to record In Sheet Y. Is what I'm looking for feasible/ even possible?
I know I can try and organize the form responses into the sheets manually, but I am trying my best to avoid that, cause its gonna take a lot of time out of the week.
Maybe there is a way to organize the form response sheet to filter the data into their appropriate sheets.
I am out of my depth and could really use some help.
You can set up a linked Sheet to the Form and then an Apps Script function that gets the data and prints it into the Sheet.
First you have to create an Installable trigger: On form submit so every time the form is submitted the Sheet will be updated
Once you have your trigger set up, you have to write the function.
I would suggest you to create variables for each sheet you want your data in.
You can select the sheet by name like: sheet.getSheetByName("MachineX")
I recommend setting up the questions in an order that allows you to say:
From question 1 to 6 -> go to "MachineX"
From question 7 to 19 -> go to "MachineY"
Now you have to iterate over the answers and get the latest responses:
- If you just want the latest response to the form you could use something like:
for (var i = formResponses.length - 1; i < formResponses.length; i++)

Google Sheets Insert Row Form

I have a running parts order list that several people use. I am trying to have the top row be a form so the user enters Qty, Part #, and Notes and presses Enter. I want it to add a row to the top of the sheet below the headers and maintain the table structure so we can filter.
Instead of using the top row, go to Tools then create form. This will make it easier to input stuff. Also no one can muck up your sheet.
Also I would read what you can post here :) I like to be friendly so I thought I'd put an answer
You should read about Google Apps Script. GAS is the easiest way to read/write data in Google Spreadsheet/Docs/Forms.
So as far as I understand from your question, you need to insert a row in Google Spreadsheet below the header directly as soon as the forms.
Step 1: Open the spreadsheet using openById(id)
Step 2: Get the worksheet in which you want to save your Google Forms data using getSheetByName(name)
Step 3: Insert row before specified position using insertRowBefore(beforePosition)
So final code should look like this.
var spreadsheet = SpreadsheetApp.openById("1BZuYFCnN_g9vn5crxbPeYlhUKwH6N3u0uT8LCmm-neM");
var sheet = spreadsheet.getSheetByName("Nov-2017");
sheet.insertRowsBefore(2);
The code above will insert only one row below spreadsheet headers. There is an alternative -> insertRowsBefore(beforePosition, howMany) if you want to insert multiple rows at a specified position.
Try this and let me know if you find any difficulties. Hope this is what you're looking for.

Carry out equations using Google Sheet Script to update database values

So I'm trying to create a simple Elo model for our table tennis league at work, I'm using the spreadsheet to generate match ups and then depending upon the winner going in and manually updating the rankings.
I attempted to try and do this (As seen below) but I was blissfully unaware that set.formula was definitely not the correct coding to be using.
Is there a way for me to carry out what I've outlined below, I essentially want to be able to click a button for Player A or Player B and have their Elo rank update on the back end and then generate a new match combination? Also how do I update the record based on a variable? Everyone has a unique player number but is there a function similar to VLOOKUP that will let me find a record and perform a formula?
I've put as many sheet callouts in the code below as I can:
var sheet =SpreadsheetApp.getActive().getSheetByName("Data");
var cell = sheet.getRange("=VLOOKUP("!MatchC18,A:C,3,False")
cell.setFormula ("=SUM(VLOOKUP(!MatchC18,A:C,3,FALSE)+!MatchA6*(1-E$4))");
cell.setFormula ("=SUM(VLOOKUP(!MatchE18,A:C,3,FALSE)+!MatchA7*(0-F$4))");
var sheet =SpreadsheetApp.getActive().getSheetByName('Match');
var cell = sheet.getRange ("C18");
cell.setFormula("=TRUNC(RANDBETWEEN(100,632))");
var sheet =SpreadsheetApp.getActive().getSheetByName('Match');
var cell = sheet.getRange ("E18");
cell.setFormula("=TRUNC(RANDBETWEEN(100,632))");
Any help will be massively appreciated!
Thanks!
As commented, your post is too broad.
Anyhow, to help you in any ways, you may use the following as additional references.
There's already an existing issue 456 in google-apps-script-issues tracker on using bulk methods such as setValues, setFormulas, etc.
and based from the thread, this issue hasn't been totally fixed yet. You may, however, try to use the given work around.
For the usage of VLOOKUP in Google Spreadsheets, more information can be found in Find Data in Google Spreadsheets with VLOOKUP.

Questions about data formatting using UiApp and google spreadsheet

Thank you in advance for any help you can provide. As background, I built a simple UiApp using GAS that I use to populate a google spreadsheet and a calendar with entries about events including time, date, location, etc. I've had it working for awhile but I want to keep improving it and I have a few questions about format and functionality.
1.) I now want the script to copy the information to a second spreadsheet, I've established how to do this, but the second spreadsheet already has some columns in use that I don't want to override and I don't want to just place the info from this Ui into the first 'X' number of columns, is there any easy way to essentially "copy these 5 columns to the first then skip and column and bring in the rest". Here is the code I have for the copy action right now:
var ss = SpreadsheetApp.openById(ssID);
var sheet = ss.getSheets()[0];
sheet.getRange(sheet.getLastRow()+1, 1, 1, 20).setValues([[new Date(), eventTitle, eventDateFrom, eventStartTimeb, eventEndTimeb, eventLocationName, eventLocationCity,eventActivity, eventLeadContact, eventNSLContact, eventContactAttending, eventDepartment, eventStaff, eventMaterials, eventCost, eventIncentive, eventMSTarget, eventSolar, eventNotes,eventRegion]]);
Also, in the same vein as this question, I've been wondering if it is possible to write something that will choose when an entry is copied to the second spreadsheet based on the value of one of the elements. For example, if eventStaff=0 or is blank, the script will copy the designated information to first spreadsheet but not the second.
2.) Date format: I added two listboxes for to capture event time start and event time end and I would like them to show up in the spreadsheet formatted as 00:00 AM/PM, but have only accomplished to get 00:00:00 or whole number so far.
3.) Using multiple elements to fill the location and events portion of calendar entries. This script works to create a basic event with start/end time and a title, but I'd like to use some of the information to fill in the location and description of an event. Is there a way for me to do this or do I need to concatenate those fields into one in able to enter them in the event creation. Current event creation code:
cal.createEvent(eventTitle,eventDateFrom,eventDateTo);
Sorry for the wall of text, if any clarification/additional code sample is needed just ask. Thank you in advance for any help/insight you might be able to provide.
Please don't be offended but I'm afraid your questions are more general programming question than GAS question, by formulating the question you almost answer it by yourself (question 1).
As for question 2, have a look to Utilities.formatDate and you'll get what you want, see also this.
Question 3: see CalendarApp documentation, createEvent, there is a set of optional arguments that suits your needs. - best regards,