This Google Apps Script fetches product data from a WooCommerce store and writes it to an active Google Sheet.
- A WooCommerce store with API access enabled.
- Google Sheets with Google Apps Script enabled.
-
WooCommerce API Credentials:
- Log in to your WooCommerce store.
- Navigate to
WooCommerce > Settings > Advanced > REST API
. - Create a new API key with
Read
permissions. - Note down the
Consumer Key
andConsumer Secret
.
-
Google Sheets:
- Open a new or existing Google Sheet.
- Go to
Extensions > Apps Script
.
-
Google Apps Script:
- Copy the contents of
script.js
into the script editor. - Replace the placeholders in the script with your WooCommerce API credentials:
const API_URL = 'https://example.com/wp-json/wc/v3'; // Replace with your WordPress site URL const CONSUMER_KEY = 'consumer key'; // Replace with your Consumer Key const CONSUMER_SECRET = 'consumer secret'; // Replace with your Consumer Secret
- Copy the contents of
-
Run the Script:
- Save the script.
- Click the
Run
button to execute the script. - Authorize the script to access your Google Sheet and make external requests.
- The script will clear any existing data in the active sheet and fetch product data from your WooCommerce store.
- The data will be written to the sheet with the following headers:
- The script logs the status of the data fetch process. You can view the logs by going to
View > Logs
in the Apps Script editor.
- Ensure that your WooCommerce API credentials are correct.
- Make sure that the WooCommerce API is enabled and accessible.
- Check the Google Apps Script logs for any error messages.
This project is licensed under the MIT License.