Giter VIP home page Giter VIP logo

mithunmanohar / woocommerce-orders-google-sheets-integration Goto Github PK

View Code? Open in Web Editor NEW
113.0 18.0 44.0 34 KB

Connect and sync order data from your WooCommerce store to Google sheets automatically. A free alternative to Zapier-WooCommerce integration that saves new WooCommerce order details to google sheets. Version V2 with improved features is now available !

Home Page: https://goo.gl/r8qnMJ

JavaScript 100.00%
googlesheets woocommerce-api woocommerce-products woocommerce-extension woocommerce-google-sheets woocommerce-order-export woocommerce-order-save

woocommerce-orders-google-sheets-integration's Introduction

woocommerce-google-sheets-integration

This google sheet syncs order data from your WooCommerce store to Google sheets automatically. A free alternative to Zapier-WooCommerce order integration.

The sheet uses the WooCommerce Rest API v2 to connect to the WooCommerce store and sync the order data to the google sheet. The sheet will fetch order details like First Name, Last Name, Billing Address, Shipping address, Phone, Email, Price, Payment method, Items, Quantity OrderId, Notes, Date, Refunds, Order key.

PS: If you are looking for an easy to setup advanced order integrations and features, please check out the zapier plugin for woo-commerce store here or inbuilt reporting plugins csv-export or order-export

NOTE: Woocommerce REST API only supports website that has https enabled. If your website is not https, consider installing SSL certificate from https://www.freessl.com/ or your hosting provider.

Below are the steps to set up the sheet:

1. Set up WooCommerce REST API in your WordPress website:

Steps can be found here: https://github.com/woocommerce/woocommerce/wiki/Getting-started-with-the-REST-API#generate-keys. You need to provide the API key and API secret generated from this step in the Google sheet.

2. Set up google sheets

If you know how to work with google app script, copy the code from .gs file to your script editor and set up your google sheet in the format of the template.

Alternatively click on the google sheets link: https://goo.gl/r8qnMJ

This sheet is read-only. Now you need to make a copy of this sheet to start using it. For that go to the File Menu in the sheet > click on Make a copy. This saves a copy of the sheet to your google drive. Now, this copy can be accessed only by you.

PLEASE KEEP YOUR API CREDENTIALS secret.

3. Set up your google sheet

In the copy of the google sheet created in step 2, enter your store URL (Should be in the format https://yourstore.com - notice that only https is supported), API Key, API secret, Date in the sheet and click on the Update button. The google sheets will ask for permission for the app to run. The sheet requires permission to 1. View and manage your spreadsheets in Google Drive, 2. Connect to an external service. It will show the app as unverified - This is because it is trying to access an external URL - the site you have given in the sheet in this case. Click on Advanced and proceed. Please feel free to take a look at the code in the script editor to see what the sheet is doing in case you are in doubt. If everything is set up correctly, the sheet will update with the order details from your woo-commerce store.

4. Set up automatic order sync

The sheet can be manually updated on click of the update button. If you want the sheet to update automatically, you can set up a trigger for the sheet. Click on Tools > Script Editor. A new window will pop up.

On that page, click on Edit > Current Projects Trigger. In the pop-up, give the name 'start_syncv2' in the first field and time driven in the second field. You can set the update frequency also here. There is an option to update sheet daily, hourly, monthly and even on opening the sheet.

'start_syncv2' is the function that invokes the script that syncs data between the google sheets and your site. Setting a trigger will trigger this process periodically based on the preferences you set.

If you face any issues or have any suggestions to improve this woocommerce orders google sheets integration tool, create a ticket at https://github.com/mithunmanohar/woocommerce-orders-google-sheets-integration/issues

Version V2 of the tool has additional features. If you want to try out the v1 of this tool, check out https://goo.gl/jAqPMz

Contributors to this project: @mithunmanohar, @petrfaitl

If you find this tool useful, you can consider buying me a coffee !

Buy Me A Coffee

woocommerce-orders-google-sheets-integration's People

Contributors

mih1dev avatar mithunmanohar avatar petrfaitl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woocommerce-orders-google-sheets-integration's Issues

New error in the code.

I'm getting this code error: TypeError: Cannot read property "orders" from undefined. (line 57, file "Code")
How can I fix it?

Address Format

Sheet is syncing correctly, but in wrong format should be : First Name, Last Name, property number, street name, Locale, Town, Post Code, Country, but is formatting as First Name, Last Name, property number, street name, ,Post Code, Locale, Town, Country

erro code

with "TypeError: Cannot read property "orders" from undefined.". How do you fix it

Script Editor not Working

When I click, Tool Script Editor to make it auto sync I get this error:

Sorry, unable to open the file at this time.
Please check the address and try again.

Sync works fine manually.

Change grain of data to orderline

Hi,

Firstly as superb solution... works perfectly!
Is there a way I can modify the existing or perhaps include a flag to allow a sync of every item in the order? If I had every row then I could aggregated the items back to an order myself, rather than having the items already aggregated (concatenated) in column I?

Thanks
Immy

Shipping method

I need to get a shipping method name in the google sheets.

What should i input into Code.gs file in order to do so? I have tried: shipping_method/class/name/zone-name, bet none of these worked, because i got undifined.

Thanks in advance

Add column to get the coupon code used in order

I´m trying to get the coupon code used by customers into the google sheets file, i have tried with " a = container.push(params[i]["coupon_lines"]);" but it just keeps saying "undefined" instead of pulling the coupon code, here is the whole code:

// Updated code to v2 Woocommerce API
function start_syncv2() {

var sheet_name = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
fetch_orders(sheet_name)

}

function fetch_orders(sheet_name) {

var ck = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name).getRange("B4").getValue();

var cs = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name).getRange("B5").getValue();

var website = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name).getRange("B3").getValue();

var manualDate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name).getRange("B6").getValue(); // Set your order start date in spreadsheet in cell B6

var m = new Date(manualDate).toISOString();




var surl = website + "/wp-json/wc/v2/orders?consumer_key=" + ck + "&consumer_secret=" + cs + "&after=" + m + "&per_page=100"; 
var url = surl
Logger.log(url)

var options =

    {
        "method": "GET",
        "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
        "muteHttpExceptions": true,

    };

var result = UrlFetchApp.fetch(url, options);

Logger.log(result.getResponseCode())
if (result.getResponseCode() == 200) {

    var params = JSON.parse(result.getContentText());
    Logger.log(result.getContentText());

}

var doc = SpreadsheetApp.getActiveSpreadsheet();

var temp = doc.getSheetByName(sheet_name);

var consumption = {};

var arrayLength = params.length;
Logger.log(arrayLength)
for (var i = 0; i < arrayLength; i++) {
    Logger.log("dfsfsdfsf")
    var a, c, d;
    var container = [];
    a = container.push(params[i]["billing"]["first_name"]);
    Logger.log(a)

    a = container.push(params[i]["billing"]["last_name"]);

    a = container.push(params[i]["billing"]["address_1"]+ " "+ params[i]["billing"]["postcode"]+ " "+ params[i]["billing"]["city"]+ " "+ params[i]["billing"]["state"]);

    a = container.push(params[i]["shipping"]["first_name"] + " "+ params[i]["shipping"]["last_name"]+" "+ params[i]["shipping"]["address_1"]+" "+params[i]["shipping"]["postcode"]+" "+params[i]["shipping"]["city"]+" "+params[i]["shipping"]["country"]+ " "+ params[i]["billing"]["state"]); 

    a = container.push(params[i]["billing"]["phone"]);

    a = container.push(params[i]["billing"]["email"]);
  
    a = container.push(params[i]["customer_note"]);
  
    a = container.push(params[i]["payment_method_title"]);
  
    c = params[i]["line_items"].length;

    var items = "";
    var total_line_items_quantity = 0;
    for (var k = 0; k < c; k++) {
      var item, item_f, qty, meta;

        item = params[i]["line_items"][k]["name"];

        qty = params[i]["line_items"][k]["quantity"];
      

        item_f = qty + " x " + item;

        items = items + item_f + ",\n";

        total_line_items_quantity += qty;
    }
  

    a = container.push(items);
  
    a = container.push(total_line_items_quantity); // Quantity

    a = container.push(params[i]["total"]); //Price
    
    a = container.push(params[i]["discount_total"]); // Discount
    
    d = params[i]["refunds"].length;
  
    var refundItems = "";
  
    var refundValue = 0;
  
    for (var r = 0; r < d; r++) {
      var item, item_f, value;

        item = params[i]["refunds"][r]["reason"];

        value = params[i]["refunds"][r]["total"];
        
        refundValue += parseInt(value);

        item_f = value +" - "+ item;

        refundItems += item_f + ",\n";

    }
  
    
  
    a = container.push(refundValue); //Refunded value from order
  
    a = container.push(parseFloat(container[10]) + refundValue); // Total minus refund
  
    a = container.push(refundItems); //Refunded items from order

    a = container.push(params[i]["id"]); 

    a = container.push(params[i]["date_created"]);
  
    a = container.push(params[i]["date_modified"]);
  
    a = container.push(params[i]["status"]);
  
    a = container.push(params[i]["order_key"]);
  


    var doc = SpreadsheetApp.getActiveSpreadsheet();

    var temp = doc.getSheetByName(sheet_name);

    temp.appendRow(container);

// Logger.log(params[i]);

    removeDuplicates(sheet_name);
}

}

function removeDuplicates(sheet_name) {

var doc = SpreadsheetApp.getActiveSpreadsheet();

var sheet = doc.getSheetByName(sheet_name);

var data = sheet.getDataRange().getValues();

var newData = new Array();

for (i in data) {

    var row = data[i];
  /*  TODO feature enhancement in de-duplication
    var date_modified =row[row.length-2];
  
    var order_key = row[row.length];
  
    var existingDataSearchParam = order_key + "/" + date_modified; 
   */

    var duplicate = false;

    for (j in newData) {
      
      var rowNewData = newData[j];
      
      var new_date_modified =rowNewData[rowNewData.length-2];
      
      var new_order_key = rowNewData[rowNewData.length];
      
      //var newDataSearchParam = new_order_key + "/" + new_date_modified; // TODO feature enhancement in de-duplication

      if(row.join() == newData[j].join()) {
            duplicate = true;

        }
      
      // TODO feature enhancement in de-duplication
      /*if (existingDataSearchParam == newDataSearchParam){
        duplicate = true;
      }*/

    }
    if (!duplicate) {
        newData.push(row);
    }
}
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);

}

Sync 100 orders only

Hello mithunmanohar,
Code is excellent but i am getting only 100 orders in sheets. I want orders from entered date to current date. how i get please help me.

New row is added after order status changes

Right now when the product status changes, it adds a new row in the sheet. Ideally, it shouldn't do that. Either it should change the status in the same row or delete the previous row. It will help in having no redundant data. I've kind of fixed this locally. See if you add the change in the script or I can do a PR.

Suggestion: Move the configuration fields in a separate Sheet, say "Config". And download the orders in a separate sheet say
"Orders". It will be much easier to manage the orders' data.

Delete only rows with the same OrderID

Hi,

Great code :)
I'm wondering if you could help me with adjusting the code...
After each new order comes in I add some additional data in the last few columns.
When new order comes in, it does not delete the one where I added new data in last few columns.
So I would like to delete duplicates based on OrderID. Not the whole row.
Can you help me with that?

Thank you!

Regards,
S

orders vs date value

Hi,

I'm testing the script and as far as I can see, the date value doesn't produce any change no matter what value I add. I keep getting the same 100 (recent?) orders.
Also I'm curious why the API key also needs the write permission.

Cheers!

Error of "orders" from undefined.

TypeError: Cannot read property "orders" from undefined. (line 57, file "wc-gc-integration")

We are facing above error while running "start_sync" function.

Query

Thank you for script we are searching for this script since long time

But we post every item in seperate row ... just like this http://prntscr.com/jpg38l

Is that possible we can get every item in a separate row ?
Is that possible to get image link of every item ?

Sync Orders

Dear Developer,
first of all I want to thank you for making this project public! I am still a beginner and somehow the sync orders button wont appear. How can I link .gs file with the spreadsheet?
Best regards
Patrick Hilpold

Custom fields

Is it possible to get custom fields from woocommerce to the googlesheet?

If so, how/where in the script do I need to modify?

I am able to get the usual stuff without any problems however I have a few custom fields which I would like to add to the google sheet.

Woocommerce product integration

Hello, how are you? I would like to know if you have any code or opensorce option for integrating and synchronizing Woocommerce products and Google Sheets Let it also be an alternative to zapier. I need a solution to launch the products on the spreadsheets, and the product data to be synchronized. Any options or suggestions? Thankful!

Adding columns with orders' custom fields

Hi there, and thanks for sharing this tool.
In our small store we need to acquire some extra info thus we created custom fields in the checkout (such as Vat number and others).
Is there a way to add this data to the sheet too?
Many thanks

Having trouble getting orders from the past

Hi,

I have installed your code and are playing around with it. I set the Fetch Data interval (hrs) to 2000. I would like to go back further if possible.

I can only get the data from a few days ago.

Do you have a work around for this?

Thanks
Wes

Feature request: Update an order from Google Sheets

Be able to update orders from Google Sheets

While waiting for an equivalent functionality, I added a last column for a direct link to the order to modify it:
a = container.push(website +"/wp-admin/post.php?post="+ params[i]["id"]+"&action=edit");

Limited quantity of orders

Hi !

The script is working very well and thanks for creating it !
My only issue is that only few of my past orders appear in my file whereas I would like to see all my past orders. Is it something to do with the Fetch Data interval ? I tried to put a higher number but i still can only see few of my orders, not all

Getting 404 error while fetching orders

I am currently using your script with latest version of Woocommerce and Wordpress. In that I have changed url given below:
==> var surl = website + "index.php/wc-api/v3/orders?consumer_key=" + ck + "&consumer_secret=" + cs + "&filter[created_at_min]=" + n

But it is returning 404 for "getResponseCode" and "getContentText" is returning error given below:
==>"{"errors":[{"code":"woocommerce_api_authentication_error","message":"oauth_consumer_key parameter is missing"}]}"

Could you please help me why it is occurring? I have added all details as per the documentation.

Thank you.

Adding WooCommerce Custom Fields to Google Spreadsheet

I have use a custom field in my WooCommerce orders that I'd like to add to the Google spreadsheet.

Does anyone know the exact code to write in the Script Editor in order to add custom fields? I created a column entitled "Delivery Date" and then added this code into the Script Editor:

a = container.push(params[i]["delivery_date"]);

However, when I run the script, I just get "undefined" in the new column.

Cannot read property "orders" from undefined.

This is the error code I get when I try and run the script. I already tested it in postman and it works like a gem.

I looked into the execution logs and saw that the function Logger.log(result.getResponseCode()) returns a 401, so params is never set.

advice?

Order Date timezone

The default time zone is UTC.

if my Country is UTC+1 、UTC+5.....

How to modify Order Date timezone

Feature request : integrate stock qty

hello , thanks alot for your help .. i need the same function to integrate stock qty , and i will be much grateful if the integration is two way .. from google sheet to wc inventory and versa .. thanks in advance

Add new entries on top of the excel

When you insert the data from the orders it would be better for the user to recieve the latest on top of the excel, also a seperator after each data insert would be cool so the user can easily see the new data.

Does it have a 7 day limit?

It seems like the orders from 8 days ago and further, aren't imported, is this a limitation or can I import historical data?

Product Variations

Is there a way to add functionality so product variations or custom fields for products are transmitted as well? Right now only the item name is sent without any of the additional product details.

Can't sign in to run app

When trying out this app, I set it up on my account, then click the 'Sync' button, and it comes up saying "Authorization Required - A script attached to this document needs your permission to run.", so i click Authorize, log into my Google account and the screen then says:
"Sign in with Google temporarily disabled for this app.
This app has not been verified yet by Google in order to use Google Sign In."

So googling it, and looking through the issues here, it looks like we need to verify the app. But to verify, it sends me to the Google Cloud platform, and that's where I'm not sure what to do. I have projects there, but none associated with this one - and I'm not sure how to associate a Sheets Script with a project....

Anyone able to do this and can direct me in the proper procedure?

"date_created"

Hi,
When I run the script, the instruction:
container.push(params[i]["date_created"]);
gives me this type of results: 2020-06-07T20:41:42

How can I get a result without the "T", like 2020-06-07 20:41:42

Thanks in advance
carlos

Only 10 orders

I don't know why i'm just getting the last 10 orders. The date is ok. But I can't get all the orders I have.
Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.